From 779f697ffb143cb239a0a4473152ee2542155a0e Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Tue, 26 Mar 2013 23:30:04 +0100 Subject: [PATCH] Fix yield_ms(). This fixes https://code.google.com/p/singularity-viewer/issues/detail?id=714 The problem was a typo in AIStateMachine::sleep, >= should have been <= which caused a state machine that uses yield_ms() to never run anymore when next run it already should have run again. AIFilePicker is the only state machine that currently uses yield_ms and I hadn't spotted this because I don't have plugin messages on by default which made my viewer just that much faster that it the yield never expired the first run already (causing it to expire immediately). The rest of the changes in this commit are just minor improvements / conformation to the EXAMPLE_CODE in aistatemachine.cpp. --- indra/aistatemachine/aistatemachine.h | 2 +- indra/newview/statemachine/aifilepicker.cpp | 14 ++++---------- indra/newview/statemachine/aifilepicker.h | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/indra/aistatemachine/aistatemachine.h b/indra/aistatemachine/aistatemachine.h index dffd93c7d..10031a834 100644 --- a/indra/aistatemachine/aistatemachine.h +++ b/indra/aistatemachine/aistatemachine.h @@ -296,7 +296,7 @@ class AIStateMachine : public LLThreadSafeRefCount return false; else if (mSleep < 0) ++mSleep; - else if ((U64)mSleep >= current_time) + else if ((U64)mSleep <= current_time) mSleep = 0; return mSleep != 0; } diff --git a/indra/newview/statemachine/aifilepicker.cpp b/indra/newview/statemachine/aifilepicker.cpp index c3675c4e1..418d83955 100644 --- a/indra/newview/statemachine/aifilepicker.cpp +++ b/indra/newview/statemachine/aifilepicker.cpp @@ -46,14 +46,6 @@ #include "llwindowsdl.h" #endif - -enum filepicker_state_type { - AIFilePicker_initialize_plugin = AIStateMachine::max_state, - AIFilePicker_plugin_running, - AIFilePicker_canceled, - AIFilePicker_done -}; - char const* AIFilePicker::state_str_impl(state_type run_state) const { switch(run_state) @@ -63,6 +55,7 @@ char const* AIFilePicker::state_str_impl(state_type run_state) const AI_CASE_RETURN(AIFilePicker_canceled); AI_CASE_RETURN(AIFilePicker_done); } + llassert(false); return "UNKNOWN STATE"; } @@ -361,6 +354,7 @@ void AIFilePicker::multiplex_impl(state_type run_state) { if (!plugin->isPluginRunning()) { + yield(); break; // Still initializing. } @@ -457,7 +451,7 @@ void AIFilePicker::receivePluginMessage(const LLPluginMessage &message) if (message_name == "canceled") { LL_DEBUGS("Plugin") << "received message \"canceled\"" << LL_ENDL; - advance_state(AIFilePicker_canceled); + set_state(AIFilePicker_canceled); } else if (message_name == "done") { @@ -468,7 +462,7 @@ void AIFilePicker::receivePluginMessage(const LLPluginMessage &message) { mFilenames.push_back(*filename); } - advance_state(AIFilePicker_done); + set_state(AIFilePicker_done); } else { diff --git a/indra/newview/statemachine/aifilepicker.h b/indra/newview/statemachine/aifilepicker.h index a5ee00a61..0058ea2f0 100644 --- a/indra/newview/statemachine/aifilepicker.h +++ b/indra/newview/statemachine/aifilepicker.h @@ -151,7 +151,21 @@ new AIFilePicker // Objects of this type can be reused multiple times, see // also the documentation of AIStateMachine. class AIFilePicker : public AIStateMachine { +protected: + // The base class of this state machine. + typedef AIStateMachine direct_base_type; + + enum filepicker_state_type { + AIFilePicker_initialize_plugin = direct_base_type::max_state, + AIFilePicker_plugin_running, + AIFilePicker_canceled, + AIFilePicker_done + }; public: + static state_type const max_state = AIFilePicker_done + 1; // One beyond the largest state. + +public: + // The derived class must have a default constructor. AIFilePicker(void); // Create a dynamically created AIFilePicker object.