From 7c022d6061bcf7f7419fa2c12ac4ba0fa0679117 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Sun, 15 Jul 2012 22:51:14 +0200 Subject: [PATCH] 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. --- indra/newview/statemachine/aistatemachine.cpp | 2 +- indra/newview/statemachine/aistatemachine.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/indra/newview/statemachine/aistatemachine.cpp b/indra/newview/statemachine/aistatemachine.cpp index db181ce45..94cb9da59 100644 --- a/indra/newview/statemachine/aistatemachine.cpp +++ b/indra/newview/statemachine/aistatemachine.cpp @@ -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) diff --git a/indra/newview/statemachine/aistatemachine.h b/indra/newview/statemachine/aistatemachine.h index 650e7f296..237c466ea 100644 --- a/indra/newview/statemachine/aistatemachine.h +++ b/indra/newview/statemachine/aistatemachine.h @@ -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; }