Don't crash on exit.

When a new state machine was just created, so run() had already
been called but it never did really run yet so running() would
return false; then abort() wasn't called in flush(), causing
the subsequent mainloop call to actually try and startup the
state machine, which then crashed because Debug Settings
mechanism is already destroyed at that point (and in general,
we really don't want anything to run: it does unpredictable
things).

With this fix, also state machines that were just created are
aborted, resulting actuall in a kill without delete, and subsequently
a clean delete from the mainloop.
This commit is contained in:
Aleric Inglewood
2012-07-15 22:51:14 +02:00
parent 14e5b46687
commit 7c022d6061
2 changed files with 4 additions and 1 deletions

View File

@@ -603,7 +603,7 @@ void AIStateMachine::flush(void)
for (active_statemachines_type::iterator iter = active_statemachines.begin(); iter != active_statemachines.end(); ++iter)
{
AIStateMachine& statemachine(iter->statemachine());
if (statemachine.running())
if (statemachine.abortable())
statemachine.abort();
}
for (int batch = 0;; ++batch)

View File

@@ -350,6 +350,9 @@ class AIStateMachine {
//! Return true if the derived class is running (also when we are idle).
bool running(void) const { return mState == bs_run; }
//! Return true if it's safe to call abort.
bool abortable(void) const { return (mState == bs_run && (!mIdle || is_main_thread())) || mState == bs_initialize; }
//! Return true if the derived class is running but idle.
bool waiting(void) const { return mState == bs_run && mIdle; }