Skip to content

Commit 876a1d3

Browse files
Goober5000claude
andcommitted
fix CTD when LuaSEXP evaluates a subsystem on an absent ship
The OPF_SUBSYSTEM argument-conversion path in LuaSEXP only verified has_shipp() before calling ship_entry->objp(). A ship registry entry retains its shipnum after the ship is destroyed or departed, but its objnum is reset to -1, so objp() either asserts (debug) or dereferences Objects[-1] (release) when the entry is looked up by Lua scripting during, for example, an OnMissionAboutToEnd hook. Tighten the check to has_objp() so absent ships short-circuit to an empty handle, and correct the early-return type from l_Ship to l_Subsystem. Apply the matching type correction to OPF_DOCKER_POINT, which has the same return-type mismatch but no CTD because it never dereferences objp(). Fixes scp-fs2open#7206. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 96a60eb commit 876a1d3

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

code/parse/sexp/LuaSEXP.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,13 @@ luacpp::LuaValue LuaSEXP::sexpToLua(int node, int argnum, int parent_node) const
304304

305305
auto ship_entry = eval_ship(this_node);
306306

307-
if (!ship_entry || !ship_entry->has_shipp()) {
308-
// Name is invalid
309-
return LuaValue::createValue(_action.getLuaState(), l_Ship.Set(object_h()));
307+
if (!ship_entry || !ship_entry->has_objp()) {
308+
// Ship is not present in the mission (never arrived, destroyed, or departed)
309+
return LuaValue::createValue(_action.getLuaState(), l_Subsystem.Set(ship_subsys_h()));
310310
}
311311

312312
ship_subsys* ss = ship_get_subsys(ship_entry->shipp(), name);
313-
313+
314314
return LuaValue::createValue(_action.getLuaState(), l_Subsystem.Set(ship_subsys_h(ship_entry->objp(), ss)));
315315
}
316316
case OPF_DOCKER_POINT: {
@@ -334,7 +334,7 @@ luacpp::LuaValue LuaSEXP::sexpToLua(int node, int argnum, int parent_node) const
334334
auto ship_entry = eval_ship(this_node);
335335
if (!ship_entry || !ship_entry->has_shipp()) {
336336
// Name is invalid
337-
return LuaValue::createValue(_action.getLuaState(), l_Ship.Set(object_h()));
337+
return LuaValue::createValue(_action.getLuaState(), l_Dockingbay.Set(dockingbay_h()));
338338
}
339339

340340
auto docker_pm = model_get(Ship_info[ship_entry->shipp()->ship_info_index].model_num);

0 commit comments

Comments
 (0)