Fixed Event Hander's copy constructor and copy assignments
It was missing to save the event before connecting to it. (#2026) Signed-off-by: moraaar <moraaar@amazon.com>
This commit is contained in:
@@ -27,11 +27,17 @@ namespace AZ
|
||||
template <typename... Params>
|
||||
EventHandler<Params...>::EventHandler(const EventHandler& rhs)
|
||||
: m_callback(rhs.m_callback)
|
||||
, m_event(rhs.m_event)
|
||||
{
|
||||
// Copy the callback function, then perform a Connect with the new event
|
||||
if (rhs.m_event)
|
||||
// Copy the callback and event, then perform a Connect to the event
|
||||
if (m_callback && m_event)
|
||||
{
|
||||
rhs.m_event->Connect(*this);
|
||||
m_event->Connect(*this);
|
||||
}
|
||||
else
|
||||
{
|
||||
// It was not possible to connect to the event, set it to nullptr
|
||||
m_event = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,9 +71,16 @@ namespace AZ
|
||||
{
|
||||
Disconnect();
|
||||
m_callback = rhs.m_callback;
|
||||
if (rhs.m_event)
|
||||
m_event = rhs.m_event;
|
||||
// Copy the callback and event, then perform a Connect to the event
|
||||
if (m_callback && m_event)
|
||||
{
|
||||
rhs.m_event->Connect(*this);
|
||||
m_event->Connect(*this);
|
||||
}
|
||||
else
|
||||
{
|
||||
// It was not possible to connect to the event, set it to nullptr
|
||||
m_event = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user