Commit 94c3ec9e authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

EventManager: Copy the user callback instead of holding a reference.

Not holding a copy is the highway to dangling references
parent 6297c12a
...@@ -92,9 +92,9 @@ private: ...@@ -92,9 +92,9 @@ private:
private: private:
// Deduced type is Func& in case of lvalue; Func in case of rvalue. // Deduced type is Func& in case of lvalue; Func in case of rvalue.
// So we hold a reference to the callback when passed a lvalue, we // We decay the type to ensure we either copy or take ownership.
// copy construct it when passing a rvalue // Taking a reference would quite likely lead to unexpected behavior
Func m_userCallback; typename std::decay<Func>::type m_userCallback;
// EventManager always outlive EventHandler, no need for smart pointer // EventManager always outlive EventHandler, no need for smart pointer
EventManager* m_eventManager; EventManager* m_eventManager;
Wrapper m_wrapper; Wrapper m_wrapper;
......
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