Skip to content

Fix crash when P_ZMovement calls from Lua removes the object

Hanicef requested to merge Hanicef/SRB2:fix-zmovement-remove-crash into next

If P_ZMovement or P_SceneryZMovement is called from Lua where the object's state is set for removal in the call function, the game crashes. This is caused by a missing P_MobjWasRemoved check within the Lua handlers that follows these native function calls, which causes it to attempt to fetch the object state when there no longer is an object, and thus triggering the crash.

The following Lua script reproduces the issue:

local mo = P_SpawnMobj(0, 0, 0, MT_SMALLBUBBLE)
P_SetOrigin(mo, mo.x, mo.y, mo.ceilingz)
P_SceneryZMovement(mo)

mo = P_SpawnMobj(0, 0, 0, MT_SPIKE)
mo.health = 0
P_SetOrigin(mo, mo.x, mo.y, mo.floorz)
P_ZMovement(mo)

Merge request reports