1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-30 22:17:13 +02:00

Prevent the command destructor from dissociating the listener from the manager in destructor when the container was resized.

This commit is contained in:
Sandu Liviu Catalin
2016-07-12 03:10:38 +03:00
parent 556aeac295
commit f5777cecc7
2 changed files with 83 additions and 38 deletions

View File

@ -39,6 +39,55 @@ Guard::~Guard()
mController->m_Context = mPrevious;
}
// ------------------------------------------------------------------------------------------------
Command::Command(std::size_t hash, const String & name, Listener * ptr, const CtrPtr & ctr)
: mHash(hash), mName(name), mPtr(ptr), mObj(ptr), mCtr(ctr)
{
if (mPtr)
{
mPtr->m_Controller = mCtr; // Create controller association
}
}
// ------------------------------------------------------------------------------------------------
Command::Command(std::size_t hash, const String & name, const Object & obj, const CtrPtr & ctr)
: mHash(hash), mName(name), mPtr(obj.Cast< Listener * >()), mObj(obj), mCtr(ctr)
{
if (mPtr)
{
mPtr->m_Controller = mCtr; // Create controller association
}
}
// ------------------------------------------------------------------------------------------------
Command::Command(std::size_t hash, const String & name, Object && obj, const CtrPtr & ctr)
: mHash(hash), mName(name), mPtr(obj.Cast< Listener * >()), mObj(obj), mCtr(ctr)
{
if (mPtr)
{
mPtr->m_Controller = mCtr; // Create controller association
}
}
// ------------------------------------------------------------------------------------------------
Command::Command(std::size_t hash, const String & name, Listener * ptr, const Object & obj, const CtrPtr & ctr)
: mHash(hash), mName(name), mPtr(ptr), mObj(obj), mCtr(ctr)
{
if (mPtr)
{
mPtr->m_Controller = mCtr; // Create controller association
}
}
// ------------------------------------------------------------------------------------------------
Command::Command(std::size_t hash, const String & name, Listener * ptr, Object && obj, const CtrPtr & ctr)
: mHash(hash), mName(name), mPtr(ptr), mObj(obj), mCtr(ctr)
{
if (mPtr)
{
mPtr->m_Controller = mCtr; // Create controller association
}
}
// ------------------------------------------------------------------------------------------------
Command::~Command()
{
@ -102,12 +151,7 @@ Object & Controller::Attach(Object && obj, Listener * ptr)
}
}
// Attempt to insert the command
m_Commands.emplace_back(hash, name, ptr, std::move(obj));
// Attempt to associate with the listener
if (m_Manager)
{
ptr->m_Controller = m_Manager->GetCtr();
}
m_Commands.emplace_back(hash, name, ptr, std::move(obj), m_Manager->GetCtr());
// Return the script object of the listener
return m_Commands.back().mObj;
}