Skip to content

Commit

Permalink
Merge pull request #1385 from Jorteck/shutdown-after-signal
Browse files Browse the repository at this point in the history
Add "ON_DESTROY_SERVER_AFTER" signal.
  • Loading branch information
mtijanic authored Jul 16, 2021
2 parents 3cd60b8 + 6dcd55f commit 66cfda3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Core/NWNXCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@ void NWNXCore::DestroyServerHandler(CAppManager* app)

g_core->m_destroyServerHook.reset();
app->DestroyServer();

MessageBus::Broadcast("NWNX_CORE_SIGNAL", { "ON_DESTROY_SERVER_AFTER" });

g_core->Shutdown();

RestoreCrashHandlers();
Expand Down
16 changes: 12 additions & 4 deletions Plugins/DotNET/DotNETExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,18 @@ static void RegisterHandlers(AllHandlers *handlers, unsigned size)
MessageBus::Subscribe("NWNX_CORE_SIGNAL",
[](const std::vector<std::string>& message)
{
int spBefore = Utils::PushScriptContext(Constants::OBJECT_INVALID, 0, false);
s_handlers.SignalHandler(message[0].c_str());
int spAfter = Utils::PopScriptContext();
ASSERT_MSG(spBefore == spAfter, "spBefore=%x, spAfter=%x", spBefore, spAfter);
// We will crash the server if we try to create a script context after the server is destroyed.
if (message[0] == "ON_DESTROY_SERVER_AFTER")
{
s_handlers.SignalHandler(message[0].c_str());
}
else
{
int spBefore = Utils::PushScriptContext(Constants::OBJECT_INVALID, 0, false);
s_handlers.SignalHandler(message[0].c_str());
int spAfter = Utils::PopScriptContext();
ASSERT_MSG(spBefore == spAfter, "spBefore=%x, spAfter=%x", spBefore, spAfter);
}
});
}

Expand Down

0 comments on commit 66cfda3

Please sign in to comment.