From 34990cd1246c4abcdd0db82cad2c3cabe5519810 Mon Sep 17 00:00:00 2001 From: Mark Suckerberg Date: Wed, 20 Nov 2024 05:04:04 -0600 Subject: [PATCH] Sanity check for null air turfs trying to update visuals (#70) * 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 --- src/turfs.rs | 21 ++++++++++++++------- src/turfs/processing.rs | 16 ++++++++++------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/turfs.rs b/src/turfs.rs index 5ba7a0bc..e7b1a8f0 100644 --- a/src/turfs.rs +++ b/src/turfs.rs @@ -528,19 +528,20 @@ fn hook_infos(src: ByondValue) -> Result { fn update_visuals(src: ByondValue) -> Result { 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() @@ -569,6 +570,12 @@ fn update_visuals(src: ByondValue) -> Result { ) .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()), } } diff --git a/src/turfs/processing.rs b/src/turfs/processing.rs index 42d2a145..57299314 100644 --- a/src/turfs/processing.rs +++ b/src/turfs/processing.rs @@ -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(()) })));