Fix segfault when trying to spawn an MT_PLAYER from Lua

This commit is contained in:
Hanicef 2024-01-23 22:43:25 +01:00
parent cf7adfc8ac
commit 02811b72f6
3 changed files with 19 additions and 5 deletions

View file

@ -641,7 +641,7 @@ static int lib_pSpawnMobj(lua_State *L)
NOHUD NOHUD
INLEVEL INLEVEL
NOSPAWNNULL NOSPAWNNULL
LUA_PushUserdata(L, P_SpawnMobj(x, y, z, type), META_MOBJ); LUA_PushUserdata(L, P_SpawnMobj(x, y, z, type, NULL), META_MOBJ);
return 1; return 1;
} }
@ -657,7 +657,7 @@ static int lib_pSpawnMobjFromMobj(lua_State *L)
NOSPAWNNULL NOSPAWNNULL
if (!actor) if (!actor)
return LUA_ErrInvalid(L, "mobj_t"); return LUA_ErrInvalid(L, "mobj_t");
LUA_PushUserdata(L, P_SpawnMobjFromMobj(actor, x, y, z, type), META_MOBJ); LUA_PushUserdata(L, P_SpawnMobjFromMobj(actor, x, y, z, type, NULL), META_MOBJ);
return 1; return 1;
} }

View file

@ -328,7 +328,7 @@ boolean P_CheckDeathPitCollide(mobj_t *mo);
boolean P_CheckSolidLava(ffloor_t *rover); boolean P_CheckSolidLava(ffloor_t *rover);
void P_AdjustMobjFloorZ_FFloors(mobj_t *mo, sector_t *sector, UINT8 motype); void P_AdjustMobjFloorZ_FFloors(mobj_t *mo, sector_t *sector, UINT8 motype);
mobj_t *P_SpawnMobjFromMobj(mobj_t *mobj, fixed_t xofs, fixed_t yofs, fixed_t zofs, mobjtype_t type); mobj_t *P_SpawnMobjFromMobj(mobj_t *mobj, fixed_t xofs, fixed_t yofs, fixed_t zofs, mobjtype_t type, ...);
mobj_t *P_SpawnMissile(mobj_t *source, mobj_t *dest, mobjtype_t type); mobj_t *P_SpawnMissile(mobj_t *source, mobj_t *dest, mobjtype_t type);
mobj_t *P_SpawnXYZMissile(mobj_t *source, mobj_t *dest, mobjtype_t type, fixed_t x, fixed_t y, fixed_t z); mobj_t *P_SpawnXYZMissile(mobj_t *source, mobj_t *dest, mobjtype_t type, fixed_t x, fixed_t y, fixed_t z);

View file

@ -14420,15 +14420,29 @@ void P_FlashPal(player_t *pl, UINT16 type, UINT16 duration)
// Spawns an object with offsets relative to the position of another object. // Spawns an object with offsets relative to the position of another object.
// Scale, gravity flip, etc. is taken into account automatically. // Scale, gravity flip, etc. is taken into account automatically.
// //
mobj_t *P_SpawnMobjFromMobj(mobj_t *mobj, fixed_t xofs, fixed_t yofs, fixed_t zofs, mobjtype_t type) mobj_t *P_SpawnMobjFromMobj(mobj_t *mobj, fixed_t xofs, fixed_t yofs, fixed_t zofs, mobjtype_t type, ...)
{ {
va_list args;
mobj_t *newmobj; mobj_t *newmobj;
xofs = FixedMul(xofs, mobj->scale); xofs = FixedMul(xofs, mobj->scale);
yofs = FixedMul(yofs, mobj->scale); yofs = FixedMul(yofs, mobj->scale);
zofs = FixedMul(zofs, mobj->scale); zofs = FixedMul(zofs, mobj->scale);
if (type == MT_PLAYER)
{
player_t *player;
// MT_PLAYER requires an additional parameter for the player, so pass that forth.
va_start(args, type);
player = va_arg(args, player_t *);
va_end(args);
newmobj = P_SpawnMobj(mobj->x + xofs, mobj->y + yofs, mobj->z + zofs, type, player);
}
else
{
newmobj = P_SpawnMobj(mobj->x + xofs, mobj->y + yofs, mobj->z + zofs, type); newmobj = P_SpawnMobj(mobj->x + xofs, mobj->y + yofs, mobj->z + zofs, type);
}
if (!newmobj) if (!newmobj)
return NULL; return NULL;