mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-02-21 20:27:13 +01:00
Fix issue with routines never being released. Should close #14
Few other fixes and adjustments also in routines.
This commit is contained in:
parent
f5777cecc7
commit
4e05d3d285
@ -184,7 +184,7 @@ void Routine::Insert(Routine * routine, bool associate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void Routine::Remove(Routine * routine)
|
void Routine::Remove(Routine * routine, bool forget)
|
||||||
{
|
{
|
||||||
// Do we even have what to remove?
|
// Do we even have what to remove?
|
||||||
if (!routine)
|
if (!routine)
|
||||||
@ -196,7 +196,7 @@ void Routine::Remove(Routine * routine)
|
|||||||
do {
|
do {
|
||||||
// Search for the slot with the specified routine instance
|
// Search for the slot with the specified routine instance
|
||||||
itr = std::find_if(s_Routines.begin(), s_Routines.end(),
|
itr = std::find_if(s_Routines.begin(), s_Routines.end(),
|
||||||
[routine](Element & e) -> bool { return (e.second == routine); });
|
[routine](const Element & e) -> bool { return (e.second == routine); });
|
||||||
// Was this routine instance activated?
|
// Was this routine instance activated?
|
||||||
if (itr != s_Routines.end())
|
if (itr != s_Routines.end())
|
||||||
{
|
{
|
||||||
@ -207,7 +207,14 @@ void Routine::Remove(Routine * routine)
|
|||||||
// Reset the routine instance slot
|
// Reset the routine instance slot
|
||||||
routine->m_Slot = 0xFFFF;
|
routine->m_Slot = 0xFFFF;
|
||||||
// Release any strong reference to this routine instance
|
// Release any strong reference to this routine instance
|
||||||
Dissociate(routine);
|
if (forget)
|
||||||
|
{
|
||||||
|
Forget(routine);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Dissociate(routine);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
@ -240,11 +247,6 @@ void Routine::Execute()
|
|||||||
{
|
{
|
||||||
return; // We're done here!
|
return; // We're done here!
|
||||||
}
|
}
|
||||||
// Make sure that we have a known number of arguments
|
|
||||||
else if (m_Arguments > 14)
|
|
||||||
{
|
|
||||||
STHROWF("Routine [%s] => Out of range argument count [%d]", m_Tag.c_str(), m_Arguments);
|
|
||||||
}
|
|
||||||
// Attempt to forward the call
|
// Attempt to forward the call
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -318,6 +320,12 @@ void Routine::Execute()
|
|||||||
m_Callback.Execute(m_Arg1, m_Arg2, m_Arg3, m_Arg4, m_Arg5, m_Arg6, m_Arg7,
|
m_Callback.Execute(m_Arg1, m_Arg2, m_Arg3, m_Arg4, m_Arg5, m_Arg6, m_Arg7,
|
||||||
m_Arg8, m_Arg9, m_Arg10, m_Arg11, m_Arg12, m_Arg13, m_Arg14);
|
m_Arg8, m_Arg9, m_Arg10, m_Arg11, m_Arg12, m_Arg13, m_Arg14);
|
||||||
} break;
|
} break;
|
||||||
|
// Should not reach this point but just in case
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
m_Callback.Execute(m_Arg1, m_Arg2, m_Arg3, m_Arg4, m_Arg5, m_Arg6, m_Arg7,
|
||||||
|
m_Arg8, m_Arg9, m_Arg10, m_Arg11, m_Arg12, m_Arg13, m_Arg14);
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const Sqrat::Exception & e)
|
catch (const Sqrat::Exception & e)
|
||||||
@ -581,17 +589,10 @@ Routine::Routine(Object & env, Function & func, Interval interval, Iterator iter
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
Routine::~Routine()
|
Routine::~Routine()
|
||||||
{
|
{
|
||||||
// Remove this instance from the pool
|
|
||||||
Forget(this);
|
|
||||||
// Was the routine already terminated?
|
|
||||||
if (!m_Terminated)
|
|
||||||
{
|
|
||||||
return; // Nothing to release!
|
|
||||||
}
|
|
||||||
// Remove it from the pool
|
|
||||||
Remove(this);
|
|
||||||
// Release script resources
|
// Release script resources
|
||||||
Release();
|
Release();
|
||||||
|
// Remove it from the pool of instances, just in case
|
||||||
|
Forget(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
@ -679,6 +680,9 @@ Routine & Routine::Activate()
|
|||||||
// Make sure no slot is associated
|
// Make sure no slot is associated
|
||||||
else if (m_Slot >= s_Routines.size())
|
else if (m_Slot >= s_Routines.size())
|
||||||
{
|
{
|
||||||
|
// Keep a strong reference to the script object
|
||||||
|
Associate(this);
|
||||||
|
// Insert it into the pool of active routines
|
||||||
Insert(this);
|
Insert(this);
|
||||||
}
|
}
|
||||||
// Allow chaining
|
// Allow chaining
|
||||||
@ -690,7 +694,7 @@ Routine & Routine::Deactivate()
|
|||||||
{
|
{
|
||||||
// Validate the routine lifetime
|
// Validate the routine lifetime
|
||||||
Validate();
|
Validate();
|
||||||
// Remove it from the pool
|
// Remove it from the active pool
|
||||||
Remove(this);
|
Remove(this);
|
||||||
// Allow chaining
|
// Allow chaining
|
||||||
return *this;
|
return *this;
|
||||||
@ -704,10 +708,10 @@ Routine & Routine::Terminate()
|
|||||||
{
|
{
|
||||||
STHROWF("Routine was already terminated");
|
STHROWF("Routine was already terminated");
|
||||||
}
|
}
|
||||||
// Remove it from the pool
|
|
||||||
Remove(this);
|
|
||||||
// Release script resources
|
// Release script resources
|
||||||
Release();
|
Release();
|
||||||
|
// Remove it from the active pool
|
||||||
|
Remove(this, true);
|
||||||
// Mark it as terminated
|
// Mark it as terminated
|
||||||
m_Terminated = true;
|
m_Terminated = true;
|
||||||
// Allow chaining
|
// Allow chaining
|
||||||
|
@ -80,9 +80,9 @@ protected:
|
|||||||
static void Insert(Routine * routine, bool associate = true);
|
static void Insert(Routine * routine, bool associate = true);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Insert a routine instance from the pool to not be processed.
|
* Remove a routine instance from the pool to not be processed.
|
||||||
*/
|
*/
|
||||||
static void Remove(Routine * routine);
|
static void Remove(Routine * routine, bool forget = false);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Release routine resources.
|
* Release routine resources.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user