Skip to content

Commit

Permalink
qtscript: Move initialization and shutdown to stage two to avoid memo…
Browse files Browse the repository at this point in the history
…ry leakage.

Also make sure we clear out old labels.
  • Loading branch information
perim committed Nov 24, 2012
1 parent 9fa803b commit df917d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/init.cpp
Expand Up @@ -855,11 +855,6 @@ bool stageOneInitialise(void)
return false;
}

if (!initScripts()) // Initialise the new javascript system
{
return false;
}

if (!gridInitialise())
{
return false;
Expand Down Expand Up @@ -932,11 +927,6 @@ bool stageOneShutDown(void)
return false;
}

if (!shutdownScripts())
{
return false;
}

debug(LOG_TEXTURE, "=== stageOneShutDown ===");
pie_TexShutDown();
// no map for the main menu
Expand Down Expand Up @@ -1003,6 +993,11 @@ bool stageTwoInitialise(void)
return false;
}

if (!initScripts()) // Initialise the new javascript system
{
return false;
}

// keymappings
keyClearMappings();
keyInitMappings(false);
Expand Down Expand Up @@ -1047,6 +1042,11 @@ bool stageTwoShutDown(void)
freeAllFeatures();
freeAllFlagPositions();

if (!shutdownScripts())
{
return false;
}

if (!messageShutdown())
{
return false;
Expand Down
6 changes: 5 additions & 1 deletion src/qtscriptfuncs.cpp
Expand Up @@ -2970,6 +2970,7 @@ bool unregisterFunctions(QScriptEngine *engine)
int num = groups.remove(engine);
delete psMap;
ASSERT(num == 1, "Number of engines removed from group map is %d!", num);
labels.clear();
return true;
}

Expand All @@ -2993,7 +2994,10 @@ void prepareLabels()
int id = (*j);
BASE_OBJECT *psObj = IdToPointer(id, l.player);
ASSERT(psObj, "Unit %d belonging to player %d not found", id, l.player);
groupAddObject(psObj, l.id, engine);
if (psObj)
{
groupAddObject(psObj, l.id, engine);
}
}
}
}
Expand Down

0 comments on commit df917d6

Please sign in to comment.