Fix faulty references when spawning mobjs

This commit is contained in:
Gustaf Alhäll 2023-08-29 20:56:24 +02:00 committed by Hanicef
parent dfd47733e2
commit 5c2821fb10

View file

@ -10882,6 +10882,9 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type, ...)
// increment mobj reference, so we don't get a dangling reference in case MobjSpawn calls P_RemoveMobj
mobj->thinker.references++;
if (!(mobj->flags & MF_NOTHINK))
P_AddThinker(THINK_MOBJ, &mobj->thinker);
// DANGER! This can cause P_SpawnMobj to return NULL!
// Avoid using P_RemoveMobj on the newly created mobj in "MobjSpawn" Lua hooks!
status = LUA_HookMobj(mobj, MOBJ_HOOK(MobjSpawn));