Skip to content

Commit

Permalink
physenv: testing a fix for another crash
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelIT7 committed Nov 19, 2024
1 parent 5a9cd8e commit 90f0e69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions source/modules/physenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,15 @@ Get_LuaClass(ICollisionQuery, ICollisionQuery_TypeID, "ICollisionQuery")

static Push_LuaClass(Vector, GarrysMod::Lua::Type::Vector)

inline IPhysicsEnvironment* GetPhysicsEnvironment(int iStackPos, bool bError)
static IPhysicsEnvironment* GetPhysicsEnvironment(int iStackPos, bool bError)
{
ILuaPhysicsEnvironment* pEnvironment = Get_ILuaPhysicsEnvironment(iStackPos, bError);
if (!pEnvironment->pEnvironment && bError)
ILuaPhysicsEnvironment* pLuaEnv = Get_ILuaPhysicsEnvironment(iStackPos, bError);
if (!pLuaEnv->pEnvironment && bError)
g_Lua->ThrowError(triedNull_ILuaPhysicsEnvironment.c_str());

return pEnvironment->pEnvironment;
Msg("%p (%s, %i)\n", pLuaEnv->pEnvironment, bError ? "true" : "false", iStackPos);

return pLuaEnv->pEnvironment;
}

LUA_FUNCTION_STATIC(physenv_CreateEnvironment)
Expand Down Expand Up @@ -390,11 +392,12 @@ LUA_FUNCTION_STATIC(physenv_DestroyEnvironment)
CBaseEntity* pEntity = (CBaseEntity*)pObject->GetGameData();
if (pEntity)
{

pEntity->VPhysicsUpdate(NULL); // Since the vtables are broken since ~4 functions were removed, this should currently call VPhysicsDestroyObject
}
}

physics->DestroyEnvironment(pEnvironment);
pLuaEnv->pEnvironment = NULL;
}

Delete_ILuaPhysicsEnvironment(pLuaEnv);
Expand Down
2 changes: 1 addition & 1 deletion source/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ struct LuaUserData { // ToDo: Maybe implement this also for other things?

int iReference = -1;
int iTableReference = -1;
int pAdditionalData = -1; // Used by HLTVClient.
int pAdditionalData = NULL; // Used by HLTVClient.
};

// This one is special
Expand Down

0 comments on commit 90f0e69

Please sign in to comment.