Explicit handler deinitizliation in P_Shutdown and P_FreeLevelData

This commit is contained in:
ZZYZX 2017-02-03 13:01:15 +02:00
parent 9bb4cf1c03
commit b45af599c5
3 changed files with 19 additions and 14 deletions

View file

@ -200,15 +200,11 @@ void E_InitStaticHandlers(bool map)
if (savegamerestore)
return;
// just make sure
E_Shutdown(map);
if (map) // don't initialize map handlers if restoring from savegame.
{
// delete old handlers if any.
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
{
if (!handler->IsStatic())
handler->Destroy();
}
// load non-static handlers from gameinfo
for (unsigned int i = 0; i < gameinfo.EventHandlers.Size(); i++)
{
@ -228,13 +224,6 @@ void E_InitStaticHandlers(bool map)
}
else
{
// delete old static handlers if any.
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
{
if (handler->IsStatic())
handler->Destroy();
}
for (unsigned int i = 0; i < gameinfo.EventHandlers.Size(); i++)
{
FString typestring = gameinfo.EventHandlers[i];
@ -246,6 +235,16 @@ void E_InitStaticHandlers(bool map)
}
}
void E_Shutdown(bool map)
{
// delete handlers.
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
{
if (handler->IsStatic() == !map)
handler->Destroy();
}
}
#define DEFINE_EVENT_LOOPER(name) void E_##name() \
{ \
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next) \

View file

@ -18,6 +18,8 @@ bool E_CheckHandler(DStaticEventHandler* handler);
bool E_IsStaticType(PClass* type);
// init static handlers
void E_InitStaticHandlers(bool map);
// shutdown handlers
void E_Shutdown(bool map);
// called right after the map has loaded (approximately same time as OPEN ACS scripts)
void E_WorldLoaded();

View file

@ -3424,6 +3424,8 @@ extern polyblock_t **PolyBlockMap;
void P_FreeLevelData ()
{
// [ZZ] delete per-map event handlers
E_Shutdown(true);
P_FreeMapDataBackup();
interpolator.ClearInterpolations(); // [RH] Nothing to interpolate on a fresh level.
Renderer->CleanLevelData();
@ -4189,6 +4191,8 @@ void P_Init ()
static void P_Shutdown ()
{
// [ZZ] delete global event handlers
E_Shutdown(false);
R_DeinitSpriteData ();
P_DeinitKeyMessages ();
P_FreeLevelData ();