diff -r c69806443a1c -r 72be0534cd0f src/ai/ai_threads.cpp --- a/src/ai/ai_threads.cpp Mon Jun 30 09:57:17 2008 +0000 +++ b/src/ai/ai_threads.cpp Mon Jun 30 10:26:40 2008 +0000 @@ -110,8 +110,7 @@ /* The main fiber wants this AI to die */ if (this->state == STOPPING) { - /* Suspend, and exit */ - this->state = SUSPENDED; + /* Exit the fiber */ this->Exit(); /* Here we will never come as... the fiber is dead */ @@ -151,7 +150,7 @@ void RunTick() { /* If we already stopped, don't do anything */ - if (this->state == STOPPED) return; + if (this->state == STOPPING || this->state == STOPPED) return; /* Should be called from main fiber only */ assert(stCurrentFiber() == stFind(MAIN_FIBER)); @@ -187,12 +186,12 @@ /* Should be called from main fiber only */ assert(stCurrentFiber() == stFind(MAIN_FIBER)); /* If we already stopped, don't do anything */ - if (this->state == STOPPED) return; + if (this->state == STOPPING || this->state == STOPPED) return; /* Trigger a STOPPING round */ assert(this->state == SUSPENDED); this->SwitchToState(STOPPING); - assert(this->state == SUSPENDED); + assert(this->state == STOPPING); /* Mark the fiber as STOPPED */ this->state = STOPPED; @@ -254,7 +253,7 @@ /* Switch to new state, activate fiber, and check if we are suspended again */ this->state = new_state; this->fiber->SwitchToFiber(); - assert(this->state == SUSPENDED); + assert(this->state == SUSPENDED || this->state == STOPPING); } /** @@ -287,8 +286,8 @@ } } - /* Suspend, and exit */ - this->state = SUSPENDED; + /* Stopping, and exit */ + this->state = STOPPING; this->Exit(); /* Here we will never come as... the fiber is dead */