Skip to content

Commit

Permalink
Sanity check for null air turfs trying to update visuals (Putnam3145#70)
Browse files Browse the repository at this point in the history
* Adds sanity check on visuals update callback for turfs with null air mixes

* Does the same for reaction pushing, and saves a lookup call on the turf's air

* Tidies it up

* Clippy changes and consistency

* This is actually the proper solution
  • Loading branch information
MarkSuckerberg authored Nov 20, 2024
1 parent 54c5db2 commit 34990cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
21 changes: 14 additions & 7 deletions src/turfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,19 +528,20 @@ fn hook_infos(src: ByondValue) -> Result<ByondValue> {
fn update_visuals(src: ByondValue) -> Result<ByondValue> {
use super::gas;
match src.read_var_id(byond_string!("air")) {
Err(_) => Ok(ByondValue::null()),
Ok(air) => {
Ok(air) if !air.is_null() => {
// gas_overlays: list( GAS_ID = list( VIS_FACTORS = OVERLAYS )) got it? I don't
let gas_overlays = ByondValue::new_global_ref()
.read_var_id(byond_string!("GLOB"))
.wrap_err("GLOB is null")?
.wrap_err("Unable to get GLOB from BYOND globals")?
.read_var_id(byond_string!("gas_data"))
.wrap_err("gas_data is null")?
.wrap_err("gas_data is undefined on GLOB")?
.read_var_id(byond_string!("overlays"))
.wrap_err("overlays is null")?;
.wrap_err("overlays is undefined in GLOB.gas_data")?;
let ptr = air
.read_number_id(byond_string!("_extools_pointer_gasmixture"))
.wrap_err("Gas mixture doesn't have a valid pointer")? as usize;
.read_var_id(byond_string!("_extools_pointer_gasmixture"))
.wrap_err("air is undefined on turf")?
.get_number()
.wrap_err("Gas mixture has invalid pointer")? as usize;
let overlay_types = GasArena::with_gas_mixture(ptr, |mix| {
Ok(mix
.enumerate()
Expand Down Expand Up @@ -569,6 +570,12 @@ fn update_visuals(src: ByondValue) -> Result<ByondValue> {
)
.wrap_err("Calling set_visuals")?)
}
// If air is null, clear the visuals
Ok(_) => Ok(src
.call_id(byond_string!("set_visuals"), &[])
.wrap_err("Calling set_visuals with no args")?),
// If air is not defined, it must be a closed turf. Do .othing
Err(_) => Ok(ByondValue::null()),
}
}

Expand Down
16 changes: 10 additions & 6 deletions src/turfs/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,22 @@ fn post_process() {
if should_react {
drop(sender.try_send(Box::new(move || {
let turf = ByondValue::new_ref(ValueType::Turf, id);
//turf is no longer valid for reactions
let Ok(air) = turf.read_var_id(byond_string!("air")) else {
return Ok(());
};
react_hook(air, turf).wrap_err("Reacting")?;
Ok(())
match turf.read_var_id(byond_string!("air")) {
Ok(air) if !air.is_null() => {
react_hook(air, turf).wrap_err("Reacting")?;
Ok(())
}
//turf is no longer valid for reactions
_ => Ok(()),
}
})));
}

if should_update_vis {
drop(sender.try_send(Box::new(move || {
let turf = ByondValue::new_ref(ValueType::Turf, id);

//turf is checked for validity in update_visuals
update_visuals(turf).wrap_err("Updating Visuals")?;
Ok(())
})));
Expand Down

0 comments on commit 34990cd

Please sign in to comment.