1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00

Fix the crash at shut down caused by forgetting to release the global events table object.

Include the fixes from the routines that should've been commited into the previous commit.
Take a more exception safe approach to unbinding from server events at shutdown.
This commit is contained in:
Sandu Liviu Catalin 2017-02-21 21:42:40 +02:00
parent 41e04e5167
commit e7bb68d76c
4 changed files with 59 additions and 47 deletions

View File

@ -308,6 +308,7 @@ void Core::DropEvents()
ResetSignalPair(mOnServerOption);
ResetSignalPair(mOnScriptReload);
ResetSignalPair(mOnScriptLoaded);
m_Events.Release();
}
} // Namespace:: SqMod

View File

@ -105,21 +105,13 @@ static uint8_t OnServerInitialise(void)
return ConvTo< Uint8 >::From(Core::Get().GetState());
}
// ------------------------------------------------------------------------------------------------
static void OnServerShutdown(void)
/* ------------------------------------------------------------------------------------------------
* RAII approach to unbinding the server callbacks.
*/
struct CallbackUnbinder
{
// Attempt to forward the event
try
~CallbackUnbinder()
{
// Tell the script that the server is shutting down
Core::Get().EmitServerShutdown();
// Deallocate and release everything obtained at startup
Core::Get().Terminate(true);
}
SQMOD_CATCH_EVENT_EXCEPTION(OnServerShutdown)
// See if a reload was requested (quite useless here but why not)
SQMOD_RELOAD_CHECK(g_Reload)
// The server still triggers callbacks and we deallocated everything!
_Clbk->OnServerInitialise = nullptr;
_Clbk->OnServerShutdown = nullptr;
_Clbk->OnServerFrame = nullptr;
@ -164,6 +156,25 @@ static void OnServerShutdown(void)
_Clbk->OnCheckpointExited = nullptr;
_Clbk->OnEntityPoolChange = nullptr;
_Clbk->OnServerPerformanceReport = nullptr;
}
};
// ------------------------------------------------------------------------------------------------
static void OnServerShutdown(void)
{
// The server still triggers callbacks and we deallocated everything!
const CallbackUnbinder cu;
// Attempt to forward the event
try
{
// Tell the script that the server is shutting down
Core::Get().EmitServerShutdown();
// Deallocate and release everything obtained at startup
Core::Get().Terminate(true);
}
SQMOD_CATCH_EVENT_EXCEPTION(OnServerShutdown)
// See if a reload was requested (quite useless here but why not)
SQMOD_RELOAD_CHECK(g_Reload)
}
// ------------------------------------------------------------------------------------------------

View File

@ -39,7 +39,7 @@ void Routine::Process()
// Calculate the elapsed time
const Int32 delta = Int32((s_Last - s_Prev) / 1000L);
// Process all active routines
for (Interval * itr = s_Intervals; itr != (s_Intervals + SQMOD_MAX_TASKS); ++itr)
for (Interval * itr = s_Intervals; itr != (s_Intervals + SQMOD_MAX_ROUTINES); ++itr)
{
// Is this routine valid?
if (*itr)

View File

@ -292,7 +292,7 @@ public:
// Unable to find such routine
STHROWF("Unable to find a routine with tag (%s)", tag.mPtr);
// Should not reach this point but if it did, we have to return something
return s_Instances[SQMOD_MAX_TASKS].mInst; // Intentional Buffer overflow!
return s_Instances[SQMOD_MAX_ROUTINES].mInst; // Intentional Buffer overflow!
}
/* --------------------------------------------------------------------------------------------