Commit cd4917c6 by NTAuthority

fix eventsystem-related quit/destruction crash

parent 853d4b4c
......@@ -291,10 +291,20 @@ struct EventListener
: catcher(nullptr)
{
}
~State()
{
for (auto& listener : listeners)
{
// so we won't try destructing
listener->m_hasListener = false;
}
}
};
template <typename TCallback>
EventListener(const TCallback& callback)
: m_hasListener(true)
{
m_handler = callback;
......@@ -303,7 +313,10 @@ struct EventListener
~EventListener()
{
GetState()->listeners.erase(this);
if (m_hasListener)
{
GetState()->listeners.erase(this);
}
}
void Catch()
......@@ -323,6 +336,8 @@ struct EventListener
private:
std::function<void(const T*)> m_handler;
bool m_hasListener;
// static members
public:
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