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:
private:
// 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
// copy construct it when passing a rvalue
Func m_userCallback;
// We decay the type to ensure we either copy or take ownership.
// Taking a reference would quite likely lead to unexpected behavior
typename std::decay<Func>::type m_userCallback;
// EventManager always outlive EventHandler, no need for smart pointer
EventManager* m_eventManager;
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