MantisBT - VCMI
View Issue Details
0002084VCMIAI - Adventure Mappublic2015-02-14 23:532015-04-11 18:08
Povelitel 
SXX 
normalcrashalways
closedfixed 
0.97b 
0.97c 
0002084: Crash during AI turn
Occurs on the go blue. It seems that the Deemer is attacking creatures and the game crashes.
No tags attached.
related to 0001990closed SXX hero visiting Monolit two way enters the battle if press space 
related to 0002113closed SXX interruption during AI turn 
rar Blue Deemer.rar (1,492,673) 2015-02-14 23:53
https://bugs.vcmi.eu/file_download.php?file_id=2111&type=bug
txt VCMI_Client_log.txt (501,829) 2015-02-14 23:53
https://bugs.vcmi.eu/file_download.php?file_id=2112&type=bug
txt VCMI_Server_log.txt (212,856) 2015-02-14 23:54
https://bugs.vcmi.eu/file_download.php?file_id=2113&type=bug
Issue History
2015-02-14 23:53PovelitelNew Issue
2015-02-14 23:53PovelitelStatusnew => assigned
2015-02-14 23:53PovelitelAssigned To => Warmonger
2015-02-14 23:53PovelitelFile Added: Blue Deemer.rar
2015-02-14 23:53PovelitelFile Added: VCMI_Client_log.txt
2015-02-14 23:54PovelitelFile Added: VCMI_Server_log.txt
2015-02-15 01:50SXXNote Added: 0005498
2015-02-15 02:00SXXNote Added: 0005499
2015-02-15 02:17SXXRelationship addedrelated to 0001990
2015-02-15 02:20SXXNote Added: 0005501
2015-02-15 02:40SXXNote Added: 0005503
2015-02-15 03:52SXXNote Added: 0005504
2015-02-18 11:51PovelitelNote Added: 0005539
2015-02-18 12:06SXXNote Added: 0005540
2015-02-19 04:40SXXAssigned ToWarmonger => SXX
2015-02-22 18:11SXXNote Added: 0005573
2015-02-22 18:11SXXStatusassigned => resolved
2015-02-22 18:11SXXFixed in Version => 0.97c
2015-02-22 18:11SXXResolutionopen => fixed
2015-02-28 09:41WarmongerRelationship addedrelated to 0002113
2015-04-11 18:08PovelitelStatusresolved => closed

Notes
(0005498)
SXX   
2015-02-15 01:50   
This one is reproducible with current git. Crash occur because AI trying to use hero that just died in battle.

It's likely occur because in this case lost hero handled by the "VCAI::objectRemoved" and not "VCAI::moveHeroToTile" that have appropriate exception for that case.
(0005499)
SXX   
2015-02-15 02:00   
And this is likely happen because AI don't actually expect to be attacked.
This is related to different bug of VCMI where it's behaviour isn't like one in H3. Currently if your hero stay go into the Subterranean Gate and there is moster if you press "space bar" you won't go back, but instead will attack it.

I suppose that AI try to go back, but after being attacked he get "objectRemoved" event and had to react on it. Once reacted it's try to continue movement of hero and this obviously cause crash because hero object is already removed.
(0005501)
SXX   
2015-02-15 02:20   
So here is two things need to be done:
1 - Origin of that problem 0001990 have to be fixed.
2 - And in case hero was removed during objectRemoved callback we need to make sure that this hero was properly removed from VCAI state and it's won't attempt to use it.
(0005503)
SXX   
2015-02-15 02:40   
Also this one really need to be fixed as "objectRemoved" at least used in situation when AI hero is died on "event" with guard. E.g when AI didn't expect to be attacked at all.
(0005504)
SXX   
2015-02-15 03:52   
Ok find out that objectRemoved event occur even if hero died bank, but there is difference:
1 - In "VCAI::moveHeroToTile" there is two calls of "waitTillFree".
2 - When objectRemoved event occur main AI thread wait for that.
3 - As result in 2nd case it's will throw std::runtime_error("Hero was lost!"); error
4 - Though in first case where "startHpos == dst" (e.g when hero attack monster while using subt. gate) there is no check if hero died while thread was waiting.

So dirty solution would be copy paste that check here too or the code need to be rewritten.
(0005539)
Povelitel   
2015-02-18 11:51   
The spread of the most bug causing crash on this build. I would have said so. At least for me.
(0005540)
SXX   
2015-02-18 12:06   
Yeah this problem likely appear really often. Though I'll prefer to fix origin of the problem first and only then add cleaner solution for this problem as likely this should never ever happen except it's even (which is rare and even more rarely work for the AI).
(0005573)
SXX   
2015-02-22 18:11   
So first of all I fixed 0001990 and also added additional check in code:
https://github.com/vcmi/vcmi/commit/ea46be03f3fcbe653433506db13bb73ccc30db31 [^]
So this one is resolved, but it's still questionable if that check needed at all.

Initially I think that problem may occur when hero visit event, but this code path only use when hero visit object under him while standing. In same time I find that it may happen if hero staying on creature bank may try to visit it (after get additional reinforcements).

Though this is really hard to test so for now I'll just leave check there.