Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 34990cd

Browse files
Sanity check for null air turfs trying to update visuals (Putnam3145#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
1 parent 54c5db2 commit 34990cd

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/turfs.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -528,19 +528,20 @@ fn hook_infos(src: ByondValue) -> Result<ByondValue> {
528528
fn update_visuals(src: ByondValue) -> Result<ByondValue> {
529529
use super::gas;
530530
match src.read_var_id(byond_string!("air")) {
531-
Err(_) => Ok(ByondValue::null()),
532-
Ok(air) => {
531+
Ok(air) if !air.is_null() => {
533532
// gas_overlays: list( GAS_ID = list( VIS_FACTORS = OVERLAYS )) got it? I don't
534533
let gas_overlays = ByondValue::new_global_ref()
535534
.read_var_id(byond_string!("GLOB"))
536-
.wrap_err("GLOB is null")?
535+
.wrap_err("Unable to get GLOB from BYOND globals")?
537536
.read_var_id(byond_string!("gas_data"))
538-
.wrap_err("gas_data is null")?
537+
.wrap_err("gas_data is undefined on GLOB")?
539538
.read_var_id(byond_string!("overlays"))
540-
.wrap_err("overlays is null")?;
539+
.wrap_err("overlays is undefined in GLOB.gas_data")?;
541540
let ptr = air
542-
.read_number_id(byond_string!("_extools_pointer_gasmixture"))
543-
.wrap_err("Gas mixture doesn't have a valid pointer")? as usize;
541+
.read_var_id(byond_string!("_extools_pointer_gasmixture"))
542+
.wrap_err("air is undefined on turf")?
543+
.get_number()
544+
.wrap_err("Gas mixture has invalid pointer")? as usize;
544545
let overlay_types = GasArena::with_gas_mixture(ptr, |mix| {
545546
Ok(mix
546547
.enumerate()
@@ -569,6 +570,12 @@ fn update_visuals(src: ByondValue) -> Result<ByondValue> {
569570
)
570571
.wrap_err("Calling set_visuals")?)
571572
}
573+
// If air is null, clear the visuals
574+
Ok(_) => Ok(src
575+
.call_id(byond_string!("set_visuals"), &[])
576+
.wrap_err("Calling set_visuals with no args")?),
577+
// If air is not defined, it must be a closed turf. Do .othing
578+
Err(_) => Ok(ByondValue::null()),
572579
}
573580
}
574581

src/turfs/processing.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,18 +408,22 @@ fn post_process() {
408408
if should_react {
409409
drop(sender.try_send(Box::new(move || {
410410
let turf = ByondValue::new_ref(ValueType::Turf, id);
411-
//turf is no longer valid for reactions
412-
let Ok(air) = turf.read_var_id(byond_string!("air")) else {
413-
return Ok(());
414-
};
415-
react_hook(air, turf).wrap_err("Reacting")?;
416-
Ok(())
411+
match turf.read_var_id(byond_string!("air")) {
412+
Ok(air) if !air.is_null() => {
413+
react_hook(air, turf).wrap_err("Reacting")?;
414+
Ok(())
415+
}
416+
//turf is no longer valid for reactions
417+
_ => Ok(()),
418+
}
417419
})));
418420
}
419421

420422
if should_update_vis {
421423
drop(sender.try_send(Box::new(move || {
422424
let turf = ByondValue::new_ref(ValueType::Turf, id);
425+
426+
//turf is checked for validity in update_visuals
423427
update_visuals(turf).wrap_err("Updating Visuals")?;
424428
Ok(())
425429
})));

0 commit comments

Comments
 (0)