AI enhances past its building limit

Bug #1729856 reported by GunChleoc
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
widelands
Fix Released
Undecided
Unassigned

Bug Description

I got the assert failure below:

src/ai/defaultai_warfare.cc:571: bool DefaultAI::check_trainingsites(uint32_t): Assertion `tso.bo->total_count() <= tso.bo->cnt_limit_by_aimode' failed.

Reason: the building statistics show 1 colosseum too many after saveloading. When loading from the savegames attached to this bug, we get 2 colosseums built + 1 under construction. Setting is Weak AI, which has a limit of 2.

Tags: ai crash savegame

Related branches

Revision history for this message
TiborB (tiborb95) wrote :

Do you have an idea what trainingsite it was?
Were some LUA scripting involved?

Revision history for this message
GunChleoc (gunchleoc) wrote :
Download full text (5.0 KiB)

 2: expedition max duration = 6412 (106 minutes), map area root: 144
ComputerPlayer(3): initializing as type 0
    ... DNA initialized
  3: 0 basic buildings in savegame file.
 3: AI 'very weak' mode: applying limit 2 building(s) for atlanteans_foresters_house
 3: AI 'very weak' mode: applying limit 2 building(s) for atlanteans_fishers_house
 3: AI 'very weak' mode: applying limit 2 building(s) for atlanteans_sawmill
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_smokery
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_smelting_works
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_barracks
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_farm
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_blackroot_farm
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_weaving_mill
 3: AI 'very weak' mode: applying limit 0 building(s) for atlanteans_dungeon
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_labyrinth
 3: expedition max duration = 6412 (106 minutes), map area root: 144
Message: adding warehouse for player 1 at (65, 128)
TI(5017): destination disappeared or economy mismatch -> fail
TI(4792): destination disappeared or economy mismatch -> fail
TW(1960): destination disappeared or economy mismatch -> fail
TI(3004): destination disappeared or economy mismatch -> fail
3: 4 types of ware added to warehouse 1 of 3 (cheating mode)
3: 7 types of ware added to warehouse 2 of 3 (cheating mode)
widelands: /home/bratzbert/sources/widelands/bug-1728006/src/ai/defaultai_warfare.cc:571: bool DefaultAI::check_trainingsites(uint32_t): Assertion `tso.bo->total_count() <= tso.bo->cnt_limit_by_aimode' failed.

Thread 1 "widelands" received signal SIGABRT, Aborted.
0x00007ffff541f428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
54 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) backtrace
#0 0x00007ffff541f428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1 0x00007ffff542102a in __GI_abort () at abort.c:89
#2 0x00007ffff5417bd7 in __assert_fail_base (fmt=<optimised out>,
    assertion=assertion@entry=0x1604348 "tso.bo->total_count() <= tso.bo->cnt_limit_by_aimode",
    file=file@entry=0x1604098 "/home/bratzbert/sources/widelands/bug-1728006/src/ai/defaultai_warfare.cc", line=line@entry=571,
    function=function@entry=0x1604720 <DefaultAI::check_trainingsites(unsigned int)::__PRETTY_FUNCTION__> "bool DefaultAI::check_trainingsites(uint32_t)") at assert.c:92
#3 0x00007ffff5417c82 in __GI___assert_fail (assertion=0x1604348 "tso.bo->total_count() <= tso.bo->cnt_limit_by_aimode",
    file=0x1604098 "/home/bratzbert/sources/widelands/bug-1728006/src/ai/defaultai_warfare.cc", line=571,
    function=0x1604720 <DefaultAI::check_trainingsites(unsigned int)::__PRETTY_FUNCTION__> "bool DefaultAI::check_trainingsites(uint32_t)") at assert.c:101
#4 0x00000000012bb5b2 in DefaultAI::check_trainingsites (this=0xa109fc0, gametime=7572446)
    at /home/bratzbert/sources/widelands/bug-1728006/src/ai/defaultai_warfare.cc:571
#5 0x0000000001264b7f in DefaultAI...

Read more...

Revision history for this message
TiborB (tiborb95) wrote :

check_trainingsites() (and thus this assert) is called regularly so it is mystery why this assert used to pass before saving, but fails after loading....

Revision history for this message
GunChleoc (gunchleoc) wrote :

It also doesn't fail with every load, because I got 2 autosaves for that game before it crashed.

Revision history for this message
TiborB (tiborb95) wrote :

I can get this to crash. But I created a branch (linked) where I changed assert to throw with more info (player, which building, and numbers), so please test it with the above branch and report the content of the throw, please

Revision history for this message
TiborB (tiborb95) wrote :

sorry: I CANNOT get this to crash...

Revision history for this message
GunChleoc (gunchleoc) wrote :

Here's the log - the building statistics show 1 colosseum too many. If I load from the latest savegame, I get 2 colosseums built + 1 under construction. Setting is Weak AI, which has a limit of 2.

The building statistics is lying though, there are only 2 finished colosseums and none under construction.

SaveHandler::save_game() took 3459ms
terminate called after throwing an instance of 'WException'
  what(): [/home/bratzbert/sources/widelands/bug-1729856/src/ai/defaultai_warfare.cc:573] 2 AI count of empire_colosseum exceeds an AI limit 2: actual count: 3

Thread 1 "widelands" received signal SIGABRT, Aborted.
0x00007ffff541f428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
54 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) backtrace
#0 0x00007ffff541f428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1 0x00007ffff542102a in __GI_abort () at abort.c:89
#2 0x00007ffff5d6284d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff5d606b6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff5d60701 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff5d60969 in __cxa_rethrow () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x0000000001030e7a in GameHost::run (this=0x7fffffffa340)
    at /home/bratzbert/sources/widelands/bug-1729856/src/network/gamehost.cc:679
#7 0x0000000000d7da65 in WLApplication::mainmenu_multiplayer (this=0x1b5f660)
    at /home/bratzbert/sources/widelands/bug-1729856/src/wlapplication.cc:1188
#8 0x0000000000d7cfd9 in WLApplication::mainmenu (this=0x1b5f660)
    at /home/bratzbert/sources/widelands/bug-1729856/src/wlapplication.cc:1028
#9 0x0000000000d79853 in WLApplication::run (this=0x1b5f660)
    at /home/bratzbert/sources/widelands/bug-1729856/src/wlapplication.cc:446
#10 0x0000000000d77c91 in main (argc=2, argv=0x7fffffffddb8) at /home/bratzbert/sources/widelands/bug-1729856/src/main.cc:49

Revision history for this message
GunChleoc (gunchleoc) wrote :

And a multiplayer savegame with an instant crash

GunChleoc (gunchleoc)
tags: added: savegame
summary: - DefaultAI::check_trainingsites(uint32_t): Assertion
- `tso.bo->total_count() <= tso.bo->cnt_limit_by_aimode' failed
+ Saveloading misreports the number of buildings, resulting in an AI crash
description: updated
Revision history for this message
GunChleoc (gunchleoc) wrote :

Actually, building statistics is not lying, it's just the known bug that it won't list buildings being enhanced on the bottom.

summary: - Saveloading misreports the number of buildings, resulting in an AI crash
+ AI enhances past its building limit
description: updated
Revision history for this message
GunChleoc (gunchleoc) wrote :
Download full text (3.4 KiB)

Another log from trunk, departing from the savegame in #2 - it runs for a bit before crashing, so saveloading is not involved directly in this crash:

Game: Reading Preload Data ... took 2ms
<snip>
Done reloading the game from replay
Replay writer has started
[sync] Reset
ComputerPlayer(1): initializing as type 2
    ... DNA initialized
  1: 0 basic buildings in savegame file.
 1: expedition max duration = 6412 (106 minutes), map area root: 144
ComputerPlayer(2): initializing as type 1
    ... DNA initialized
  2: 0 basic buildings in savegame file.
 2: AI 'weak' mode: applying limit 4 building(s) for empire_foresters_house
 2: AI 'weak' mode: applying limit 2 building(s) for empire_stonemasons_house
 2: AI 'weak' mode: applying limit 2 building(s) for empire_sawmill
 2: AI 'weak' mode: applying limit 2 building(s) for empire_bakery
 2: AI 'weak' mode: applying limit 2 building(s) for empire_brewery
 2: AI 'weak' mode: applying limit 3 building(s) for empire_vineyard
 2: AI 'weak' mode: applying limit 2 building(s) for empire_winery
 2: AI 'weak' mode: applying limit 2 building(s) for empire_smelting_works
 2: AI 'weak' mode: applying limit 3 building(s) for empire_farm
 2: AI 'weak' mode: applying limit 3 building(s) for empire_sheepfarm
 2: AI 'weak' mode: applying limit 2 building(s) for empire_barracks
 2: AI 'weak' mode: applying limit 2 building(s) for empire_colosseum
 2: AI 'weak' mode: applying limit 2 building(s) for empire_arena
 2: AI 'weak' mode: applying limit 1 building(s) for empire_trainingcamp
 2: expedition max duration = 6412 (106 minutes), map area root: 144
ComputerPlayer(3): initializing as type 0
    ... DNA initialized
  3: 0 basic buildings in savegame file.
 3: AI 'very weak' mode: applying limit 2 building(s) for atlanteans_foresters_house
 3: AI 'very weak' mode: applying limit 2 building(s) for atlanteans_fishers_house
 3: AI 'very weak' mode: applying limit 2 building(s) for atlanteans_sawmill
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_smokery
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_smelting_works
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_barracks
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_farm
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_blackroot_farm
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_weaving_mill
 3: AI 'very weak' mode: applying limit 0 building(s) for atlanteans_dungeon
 3: AI 'very weak' mode: applying limit 1 building(s) for atlanteans_labyrinth
 3: expedition max duration = 6412 (106 minutes), map area root: 144
Message: adding warehouse for player 1 at (65, 128)
TW(5243): destination disappeared or economy mismatch -> fail
TI(5183): destination disappeared or economy mismatch -> fail
TW(1960): destination disappeared or economy mismatch -> fail
TI(4793): destination disappeared or economy mismatch -> fail
TW(5369): destination disappeared or economy mismatch -> fail
TW(5352): destination disappeared or economy mismatch -> fail
TW(5596): destination disappeared or economy mismatch -> fail
3: 4 types of ware added to warehouse 1 of 3 (che...

Read more...

Revision history for this message
TiborB (tiborb95) wrote :

Indeed, I forgot to insert particular check into the code enhancing trainingsites. It is done now, going to propose for merge.
Though your save 1729856_ai_crash_instant.wgf is already "broken", because it already contains 3 colosseums.
Maybe we should consider plan B for such situation: AI would immediately start dismantling such sites to get in compliance...

Revision history for this message
GunChleoc (gunchleoc) wrote :

Don't worry about compliance, the assert will take care of it now that the bug is being fixed.

GunChleoc (gunchleoc)
Changed in widelands:
status: New → Fix Committed
assignee: TiborB (tiborb95) → nobody
Revision history for this message
GunChleoc (gunchleoc) wrote :

Fixed in build20-rc1

Changed in widelands:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.