mirror of https://github.com/OpenTTD/OpenTTD
(svn r25236) -Fix [FS#5547]: crash when AI is executing a command as it is bankrupted (removed from the game)
The command is placed in a queue for processing before it is bankrupted, after that the command is executed. This command yields a failure because the company does not exist, but then it still needs to call the callback. This callback tries to access the AI's virtual machine without any checks, so it starts to read a just freed pointer and segfaults.release/1.4
parent
5931faeff6
commit
001fdc3682
|
@ -238,8 +238,17 @@ ScriptInfo *AIInstance::FindLibrary(const char *library, int version)
|
|||
*/
|
||||
void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
|
||||
{
|
||||
Company::Get(_current_company)->ai_instance->DoCommandCallback(result, tile, p1, p2);
|
||||
Company::Get(_current_company)->ai_instance->Continue();
|
||||
/*
|
||||
* The company might not exist anymore. Check for this.
|
||||
* The command checks are not useful since this callback
|
||||
* is also called when the command fails, which is does
|
||||
* when the company does not exist anymore.
|
||||
*/
|
||||
const Company *c = Company::GetIfValid(_current_company);
|
||||
if (c == NULL || c->ai_instance == NULL) return;
|
||||
|
||||
c->ai_instance->DoCommandCallback(result, tile, p1, p2);
|
||||
c->ai_instance->Continue();
|
||||
}
|
||||
|
||||
CommandCallback *AIInstance::GetDoCommandCallback()
|
||||
|
|
Loading…
Reference in New Issue