Skip to content

Commit 1dbbfd0

Browse files
authored
Fix engineReplaceModel memory leak & crash for vehicles (PR #4349, Fixes #4348)
1 parent 797331f commit 1dbbfd0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Client/game_sa/CRenderWareSA.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,18 @@ RpClump* CRenderWareSA::ReadDFF(const SString& strFilename, const SString& buffe
285285

286286
// rockstar's collision hack: set the global particle emitter to the modelinfo pointer of this model
287287
if (bLoadEmbeddedCollisions)
288+
{
289+
// Vehicles have their collision loaded through the CollisionModel plugin, so we need to remove the current collision to prevent a memory leak.
290+
// This needs to be done here before reading the stream data, because plugins are read in RpClumpStreamRead.
291+
CModelInfo* modelInfo = pGame->GetModelInfo(usModelID);
292+
if (modelInfo)
293+
{
294+
if (auto* modelInfoInterface = modelInfo->GetInterface())
295+
((void(__thiscall*)(CBaseModelInfoSAInterface*))0x4C4C40)(modelInfoInterface); // CBaseModelInfo::DeleteCollisionModel
296+
}
297+
288298
RpPrtStdGlobalDataSetStreamEmbedded((void*)pPool[usModelID]);
299+
}
289300

290301
// read the clump with all its extensions
291302
RpClump* pClump = RpClumpStreamRead(streamModel);

0 commit comments

Comments
 (0)