ihhub / fheroes2

fheroes2 is a recreation of Heroes of Might and Magic II game engine.
https://ihhub.github.io/fheroes2/
GNU General Public License v2.0
2.61k stars 365 forks source link

Crash in getOriginalPassability() when loading a standard map #4527

Closed a1exsh closed 2 years ago

a1exsh commented 2 years ago

Preliminary checks

Platform

Linux

Describe the bug

Start a new single-player game using one of the standard maps, e.g. Decisions: Screenshot from 2021-10-31 10-28-59

10:24:55: [DBG_ENGINE]  main:  Free Heroes of Might and Magic II, version: 0.9.8
fheroes2: ../fheroes2/maps/maps_tiles.cpp:920: int Maps::Tiles::getOriginalPassability() const: Assertion `objectType == MP2::OBJ_REEFS' failed.
Aborted (core dumped)
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `/home/ash/src/fheroes2/fheroes2'.
Program terminated with signal SIGABRT, Aborted.
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50  ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
[Current thread is 1 (Thread 0x7f6745953e80 (LWP 27110))]
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007f6745983537 in __GI_abort () at abort.c:79
#2  0x00007f674598340f in __assert_fail_base (fmt=0x7f6745aec128 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x55779dd35570 "objectType == MP2::OBJ_REEFS", 
    file=0x55779dd34c98 "../fheroes2/maps/maps_tiles.cpp", line=920, function=<optimized out>) at assert.c:92
#3  0x00007f6745992662 in __GI___assert_fail (assertion=0x55779dd35570 "objectType == MP2::OBJ_REEFS", file=0x55779dd34c98 "../fheroes2/maps/maps_tiles.cpp", line=920, 
    function=0x55779dd35540 "int Maps::Tiles::getOriginalPassability() const") at assert.c:101
#4  0x000055779dc46c5d in Maps::Tiles::getOriginalPassability (this=0x7f66fc5303f0) at ../fheroes2/maps/maps_tiles.cpp:920
#5  0x000055779dc46c88 in Maps::Tiles::setInitialPassability (this=0x7f66fc5303f0) at ../fheroes2/maps/maps_tiles.cpp:930
#6  0x000055779dc8eb8f in World::PostLoad (this=0x55779de4be20 <World::Get()::insideWorld>, setTilePassabilities=true) at ../fheroes2/world/world.cpp:1328
#7  0x000055779dc9d9c1 in World::ProcessNewMap (this=0x55779de4be20 <World::Get()::insideWorld>) at ../fheroes2/world/world_loadmap.cpp:701
#8  0x000055779dc9cf1b in World::LoadMapMP2 (this=0x55779de4be20 <World::Get()::insideWorld>, filename="./MAPS/DECISION.MX2") at ../fheroes2/world/world_loadmap.cpp:542
#9  0x000055779dba3c9a in (anonymous namespace)::LoadNewMap () at ../fheroes2/game/game_scenarioinfo.cpp:375
#10 0x000055779dba4053 in Game::ScenarioInfo () at ../fheroes2/game/game_scenarioinfo.cpp:412
#11 0x000055779db98d40 in Game::mainGameLoop (isFirstGameRun=false) at ../fheroes2/game/game_mainmenu.cpp:122
#12 0x000055779db7c2e8 in main (argc=1, argv=0x7ffc52be64c8) at ../fheroes2/game/fheroes2.cpp:226
(gdb) 

Save file

Not needed: use a standard map.

Additional info

Looks like another regression from #4514: it works before that change.

a1exsh commented 2 years ago

I'm wondering if we should have a script for developers to quickly check if the map loader can still load all the maps present in the maps directory (at least without crashing — correctness is harder to verify).

For the CI on github we could include some random or hand-crafted maps that include as many different objects as possible to help detect such issues earlier. Wdyt?

ihhub commented 2 years ago

The crash is expected due to added assertion.