Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanity check for null air turfs trying to update visuals #70

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading