Commit cd4917c6 authored by NTAuthority's avatar NTAuthority

fix eventsystem-related quit/destruction crash

parent 853d4b4c
...@@ -291,10 +291,20 @@ struct EventListener ...@@ -291,10 +291,20 @@ struct EventListener
: catcher(nullptr) : catcher(nullptr)
{ {
} }
~State()
{
for (auto& listener : listeners)
{
// so we won't try destructing
listener->m_hasListener = false;
}
}
}; };
template <typename TCallback> template <typename TCallback>
EventListener(const TCallback& callback) EventListener(const TCallback& callback)
: m_hasListener(true)
{ {
m_handler = callback; m_handler = callback;
...@@ -303,7 +313,10 @@ struct EventListener ...@@ -303,7 +313,10 @@ struct EventListener
~EventListener() ~EventListener()
{ {
GetState()->listeners.erase(this); if (m_hasListener)
{
GetState()->listeners.erase(this);
}
} }
void Catch() void Catch()
...@@ -323,6 +336,8 @@ struct EventListener ...@@ -323,6 +336,8 @@ struct EventListener
private: private:
std::function<void(const T*)> m_handler; std::function<void(const T*)> m_handler;
bool m_hasListener;
// static members // static members
public: public:
static void Handle(const T* event) static void Handle(const T* event)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment