Skip to content

Commit 2259c87

Browse files
committed
Block name is now checked when loading IFP.
Before you could load many IFPs with same block name and it would cause memory leaks, now it's fixed.
1 parent a9a8066 commit 2259c87

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -305,28 +305,36 @@ int CLuaEngineDefs::EngineLoadIFP ( lua_State* luaVM )
305305
{
306306
// Grab the resource root entity
307307
CClientEntity* pRoot = pResource->GetResourceTXDRoot ();
308-
309-
// Create a IFP element
310-
CClientIFP* pIFP = new CClientIFP ( m_pManager, INVALID_ELEMENT_ID );
311-
312-
// Try to load the IFP file
313-
if ( pIFP->LoadIFP ( strPath, strBlockName ) )
314-
{
315-
// We can use the map to retrieve correct IFP by block name later
316-
g_pClientGame->InsertIFPPointerToMap ( strBlockName, pIFP );
317-
318-
// Success loading the file. Set parent to IFP root
319-
pIFP->SetParent ( pRoot );
320-
321-
// Return the IFP element
322-
lua_pushelement ( luaVM, pIFP );
323-
return 1;
324-
}
308+
309+
// Check whether the IFP blockname exists or not
310+
if ( g_pClientGame->GetIFPPointerFromMap ( strBlockName ) == nullptr )
311+
{
312+
// Create a IFP element
313+
CClientIFP* pIFP = new CClientIFP ( m_pManager, INVALID_ELEMENT_ID );
314+
315+
// Try to load the IFP file
316+
if ( pIFP->LoadIFP ( strPath, strBlockName ) )
317+
{
318+
// We can use the map to retrieve correct IFP by block name later
319+
g_pClientGame->InsertIFPPointerToMap ( strBlockName, pIFP );
320+
321+
// Success loading the file. Set parent to IFP root
322+
pIFP->SetParent ( pRoot );
323+
324+
// Return the IFP element
325+
lua_pushelement ( luaVM, pIFP );
326+
return 1;
327+
}
328+
else
329+
{
330+
// Delete it again
331+
delete pIFP;
332+
argStream.SetCustomError ( strFile, "Error loading IFP" );
333+
}
334+
}
325335
else
326336
{
327-
// Delete it again
328-
delete pIFP;
329-
argStream.SetCustomError ( strFile, "Error loading IFP" );
337+
argStream.SetCustomError ( strFile, "Block name already exists" );
330338
}
331339
}
332340
else

0 commit comments

Comments
 (0)