Avoid assertion in ~AIStateMachine upon viewer exit.

Force the state to bs_killed before clearing the list of statemachines
in AIEngine::flush().
This commit is contained in:
Aleric Inglewood
2013-03-28 03:01:27 +01:00
parent ac84e02018
commit c14601f7c2
2 changed files with 14 additions and 2 deletions

View File

@@ -352,8 +352,13 @@ void AIEngine::mainloop(void)
void AIEngine::flush(void) void AIEngine::flush(void)
{ {
DoutEntering(dc::statemachine, "AIEngine::flush [" << mName << "]");
engine_state_type_wat engine_state_w(mEngineState); engine_state_type_wat engine_state_w(mEngineState);
DoutEntering(dc::statemachine, "AIEngine::flush [" << mName << "]: calling force_killed() on " << engine_state_w->list.size() << " state machines.");
for (queued_type::iterator iter = engine_state_w->list.begin(); iter != engine_state_w->list.end(); ++iter)
{
// To avoid an assertion in ~AIStateMachine.
iter->statemachine().force_killed();
}
engine_state_w->list.clear(); engine_state_w->list.clear();
} }
@@ -906,6 +911,12 @@ void AIStateMachine::callback(void)
} }
} }
void AIStateMachine::force_killed(void)
{
multiplex_state_type_wat state_w(mState);
state_w->base_state = bs_killed;
}
void AIStateMachine::kill(void) void AIStateMachine::kill(void)
{ {
DoutEntering(dc::statemachine, "AIStateMachine::kill() [" << (void*)this << "]"); DoutEntering(dc::statemachine, "AIStateMachine::kill() [" << (void*)this << "]");

View File

@@ -300,8 +300,9 @@ class AIStateMachine : public LLThreadSafeRefCount
mSleep = 0; mSleep = 0;
return mSleep != 0; return mSleep != 0;
} }
void force_killed(void); // Called from AIEngine::flush().
friend class AIEngine; // Calls multiplex(). friend class AIEngine; // Calls multiplex() and force_killed().
}; };
bool AIEngine::QueueElementComp::operator()(QueueElement const& e1, QueueElement const& e2) const bool AIEngine::QueueElementComp::operator()(QueueElement const& e1, QueueElement const& e2) const