FS#3078 - AI using 'modes' incorrectly assert

Attached to Project: OpenTTD
Opened by Felix Atagong (Felix_Atagong) - Saturday, 01 August 2009, 19:42 GMT
Last edited by Thijs Marinussen (Yexo) - Thursday, 20 August 2009, 10:40 GMT
Type Bug
Category Core
Status Closed
Assigned To No-one
Operating System All
Severity High
Priority Normal
Reported Version 0.7.2-RC2
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


I have had 3 crashes in a couple of days time and this hasn't happened since at least a decade 8-)))
I have also seen in a previous post that an OpenTTD game using Dutch language crashed without a 'reason'...

*** OpenTTD Crash Report ***
Date: 2009-08-01 21:13:40
Build: 0.7.2-RC1 (0) built on Jul 15 2009 20:57:25
Reason: Assertion failed at ..\src\ai\api\ai_testmode.cpp:24: this->GetDoCommandModeInstance() == this
Language: dutch.lng
Exception C0000005 at 004FBAF6

This task depends upon

Closed by  Thijs Marinussen (Yexo)
Thursday, 20 August 2009, 10:40 GMT
Reason for closing:  Fixed
Additional comments about closing:  In r17230.
Comment by Remko Bijker (Rubidium) - Saturday, 01 August 2009, 19:45 GMT
Can you figure out which AI causes this issue?
Can you attach crash.log, crash.dmp and crash.sav?
Comment by Felix Atagong (Felix_Atagong) - Sunday, 02 August 2009, 08:32 GMT
Ooops, I was pretty sure I had attached all log and crash files... Here I go again...
I'm gonna try to find what AI did the job (I run them all, including the eye candy ones).
I also add the crash.sav that saved right after crashing.

Here are all my downloaded AI...
AdmiralAI.22.tar 389,120 17/06/2009 20:43:15
CluelessPlus.8.tar 102,400 30/07/2009 20:44:37
Convoy.11.tar 61,440 13/06/2009 20:56:52
NoCAB.1.23__r328_.tar 378,880 29/07/2009 21:32:26
OtviAI.283.tar 102,400 13/06/2009 20:56:52
PathZilla.6.tar 276,480 9/07/2009 21:26:28
PAXLink.13.tar 143,360 23/06/2009 19:56:18
StreetTraffic1.1.0.tar 51,200 13/06/2009 20:56:52
TownCars.4.tar 51,200 29/07/2009 21:32:26
Trans_AI.090713.tar 266,240 13/07/2009 21:47:41
Comment by Felix Atagong (Felix_Atagong) - Sunday, 02 August 2009, 12:23 GMT
...and again... game crashed a few seconds after the last savegame...

Comment by Felix Atagong (Felix_Atagong) - Sunday, 02 August 2009, 14:38 GMT
The previous games run smoothly until Fanioz kicks in.
Trans (v90713) causes the crash - last AI debug info is
Executing Headquarter Builder Task
then OpenTTD crashes.

Comment by Rifani Arsyad (fanioz) - Monday, 03 August 2009, 13:02 GMT
simplified script maybe something like this :

for (;;) local x = AITestMode();

Comment by Rifani Arsyad (fanioz) - Tuesday, 04 August 2009, 13:14 GMT
Actually what I've done with Trans (but simplified already).
I've fixed this in my AI locally, but not uploaded yet.
Comment by fonsinchen (fonsinchen) - Saturday, 15 August 2009, 09:45 GMT
I have a backtrace for that. It happened for me when I tried to start Rondje. It failed several times because "the AI took too long to initialize". Eventually I got this crash:

dbg: [ai] The AI died unexpectedly.
dbg: [ai] The AI died unexpectedly.
openttd: /home/alve/projekte/openttd/src/ai/api/ai_testmode.cpp:24: virtual AITestMode::~AITestMode(): Assertion `this->GetDoCommandModeInstance() == this' failed.

Program received signal SIGABRT, Aborted.
0x00007fdbe9140ed5 in raise () from /lib/
(gdb) bt
#0 0x00007fdbe9140ed5 in raise () from /lib/
#1 0x00007fdbe91423f3 in abort () from /lib/
#2 0x00007fdbe9139dc9 in __assert_fail () from /lib/
#3 0x00000000004a8f48 in ~AITestMode (this=0x2554c70) at /home/alve/projekte/openttd/src/ai/api/ai_testmode.cpp:24
#4 0x000000000055da15 in SimpleCountedObject::Release (this=0x2554c70) at /home/alve/projekte/openttd/src/misc/countedobj.cpp:20
#5 0x0000000000448065 in DefSQDestructorCallback<AITestMode> (p=0x2554c70, size=0) at /home/alve/projekte/openttd/src/ai/../script/squirrel_helper.hpp:841
#6 0x0000000000413434 in SQInstance::Release (this=0x21d2c90) at /home/alve/projekte/openttd/src/3rdparty/squirrel/squirrel/sqclass.h:131
#7 0x000000000040bcf2 in ~SQObjectPtr (this=0x218d610) at /home/alve/projekte/openttd/src/3rdparty/squirrel/squirrel/sqobject.h:257
#8 0x000000000040c226 in sqvector<SQObjectPtr>::resize (this=0x218d4d0, newsize=0, fill=@0x7ffff3d439c0) at /home/alve/projekte/openttd/src/3rdparty/squirrel/squirrel/squtils.h:54
#9 0x000000000043ce94 in SQGenerator::Kill (this=0x218d490) at /home/alve/projekte/openttd/src/3rdparty/squirrel/squirrel/sqclosure.h:61
#10 0x00000000004363c1 in SQVM::Execute (this=0x1fbfce0, closure=@0xafe340, target=35, nargs=-1, stackbase=-1, outres=@0x7ffff3d43d30, raiseerror=1, et=ET_RESUME_OPENTTD) at /home/alve/projekte/openttd/src/3rdparty/squirrel/squirrel/sqvm.cpp:869
#11 0x0000000000407da5 in sq_resumecatch (v=0x1fbfce0, suspend=10000) at /home/alve/projekte/openttd/src/3rdparty/squirrel/squirrel/sqapi.cpp:1010
#12 0x00000000006392a7 in Squirrel::Resume (this=0x1c132e0, suspend=10000) at /home/alve/projekte/openttd/src/script/squirrel.cpp:186
#13 0x000000000044a3b7 in AIInstance::GameLoop (this=0x1cd5f00) at /home/alve/projekte/openttd/src/ai/ai_instance.cpp:338
#14 0x0000000000440198 in AI::GameLoop () at /home/alve/projekte/openttd/src/ai/ai_core.cpp:69
#15 0x00000000005ccaf2 in StateGameLoop () at /home/alve/projekte/openttd/src/openttd.cpp:1163
#16 0x00000000005cde77 in GameLoop () at /home/alve/projekte/openttd/src/openttd.cpp:1242
#17 0x00000000006cfa53 in VideoDriver_SDL::MainLoop (this=0x109abe0) at /home/alve/projekte/openttd/src/video/sdl_v.cpp:501
#18 0x00000000005cec56 in ttd_main (argc=1, argv=0x7ffff3d443f8) at /home/alve/projekte/openttd/src/openttd.cpp:733
#19 0x00000000006ba79e in main (argc=1, argv=0x7ffff3d443f8) at /home/alve/projekte/openttd/src/unix.cpp:251
(gdb) up
#1 0x00007fdbe91423f3 in abort () from /lib/
#2 0x00007fdbe9139dc9 in __assert_fail () from /lib/
#3 0x00000000004a8f48 in ~AITestMode (this=0x2554c70) at /home/alve/projekte/openttd/src/ai/api/ai_testmode.cpp:24
24 assert(this->GetDoCommandModeInstance() == this);
(gdb) p this->GetDoCommandModeInstance()
$5 = (AIObject *) 0x25e0430
(gdb) p *this
$6 = {<AIObject> = {<SimpleCountedObject> = {_vptr.SimpleCountedObject = 0x731670, m_ref_cnt = 0}, <No data fields>}, last_mode = 0, last_instance = 0x0}
(gdb) p *GetDoCommandModeInstance()
$7 = {<SimpleCountedObject> = {_vptr.SimpleCountedObject = 0x72e010, m_ref_cnt = 1}, <No data fields>}