Fix crashes after detaching with uncleared event callbacks

This commit is contained in:
BenCat07 2020-05-27 10:55:16 +02:00
parent a60f52fa9d
commit 9ca31329f9
4 changed files with 18 additions and 2 deletions

View File

@ -10,6 +10,7 @@ namespace gui
{
void init();
void shutdown();
void draw();
bool handleSdlEvent(SDL_Event *event);

View File

@ -17,6 +17,7 @@
#include "hack.hpp"
#include "common.hpp"
#include "MiscTemporary.hpp"
#include "menu/GuiInterface.hpp"
#include <link.h>
#include <pwd.h>
@ -400,6 +401,10 @@ void hack::Shutdown()
delete g_pLocalPlayer;
delete g_pTeamRoundTimer;
delete g_pPlayerResource;
#if ENABLE_GUI
logging::Info("Shutting down GUI");
gui::shutdown();
#endif
if (!hack::game_shutdown)
{
logging::Info("Running shutdown handlers");

View File

@ -9,6 +9,7 @@
#include <colors.hpp>
#include <init.hpp>
#include "KeyValues.h"
#include "HookTools.hpp"
namespace event_logging
{
@ -253,7 +254,11 @@ public:
static LoggingEventListener event_listener{};
InitRoutine init([]() { g_IGameEventManager->AddListener(&event_listener, false); });
InitRoutine init([]() {
g_IGameEventManager->AddListener(&event_listener, false);
EC::Register(
EC::Shutdown, []() { g_IGameEventManager->RemoveListener(&event_listener); }, "shutdown_eventlogger");
});
bool isEnabled()
{

View File

@ -146,6 +146,11 @@ void gui::init()
init_done = true;
}
void gui::shutdown()
{
g_IGameEventManager->RemoveListener(&listener);
}
void gui::draw()
{
if (!init_done)