Skip to content

Commit

Permalink
Fix OpenTTD#7188: AI instance crash when reloading AI in a server.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuXarick committed Apr 11, 2019
1 parent 7c8e7c6 commit 6f288ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ai/ai_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
* when the company does not exist anymore.
*/
const Company *c = Company::GetIfValid(_current_company);
if (c == nullptr || c->ai_instance == nullptr) return;
if (c == nullptr || c->ai_instance == nullptr || !c->ai_instance->IsWaiting()) return;

c->ai_instance->DoCommandCallback(result, tile, p1, p2);
c->ai_instance->Continue();
Expand Down
5 changes: 5 additions & 0 deletions src/script/script_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ class ScriptInstance {
*/
bool IsSleeping() { return this->suspend != 0; }

/**
* Check if the instance is expecting an answer from a DoCommand.
*/
bool IsWaiting() { return this->suspend < 0; }

protected:
class Squirrel *engine; ///< A wrapper around the squirrel vm.
const char *versionAPI; ///< Current API used by this script.
Expand Down

0 comments on commit 6f288ac

Please sign in to comment.