Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion `isWater()' failed #8440

Closed
2 tasks done
kuuff opened this issue Feb 29, 2024 · 4 comments · Fixed by #8450
Closed
2 tasks done

Assertion `isWater()' failed #8440

kuuff opened this issue Feb 29, 2024 · 4 comments · Fixed by #8450
Assignees
Labels
bug Something doesn't work crash Application crashes. The highest level of priority high priority Very critical change needed immediately
Milestone

Comments

@kuuff
Copy link

kuuff commented Feb 29, 2024

Preliminary checks

Platform

Linux

Describe the bug

Game crushes when I finish my turn. I checked on the latest snapshot it crashes too, but the "additional info" is for origin/master. This console log missed my actions in the game, but I just load game (save attached) and finish my turn.

Save file

bug.zip

Additional info

$ git log -1
commit cbe1879c023bbc89b14120c44be0ef92040c972c (HEAD -> master, origin/master, origin/HEAD)
Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Thu Feb 29 10:37:10 2024 +1100

    Update translation files (#8439)
$ gdb ./fheroes2
Reading symbols from ./fheroes2...
(gdb) run
Starting program: /home/user/src/fheroes2/fheroes2
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
fheroes2 engine, version: 1.0.12
[Detaching after fork from child process 16750]
[New Thread 0x7ffff6e006c0 (LWP 16751)]
29.02.2024 17:05:42: [DBG_ENGINE]	Init:  Expected music initialization flags as 57 but received 0
...
[blah-blah-blah]
...
29.02.2024 17:05:55: [DBG_GAME]	PlayMusicImp:  Cannot find a file for 28 track.
fheroes2: /home/rgo/src/fheroes2/src/fheroes2/maps/maps_tiles.cpp:617: void Maps::Tiles::setBoat(int, int): Assertion `isWater()' failed.

Thread 1 "fheroes2" received signal SIGABRT, Aborted.
0x00007ffff78a4e9c in __pthread_kill_implementation () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff78a4e9c in __pthread_kill_implementation () from /lib64/libc.so.6
#1  0x00007ffff78565c2 in raise () from /lib64/libc.so.6
#2  0x00007ffff783f4ed in abort () from /lib64/libc.so.6
#3  0x00007ffff783f415 in __assert_fail_base.cold () from /lib64/libc.so.6
#4  0x00007ffff784f142 in __assert_fail () from /lib64/libc.so.6
#5  0x00005555559b16e7 in Maps::Tiles::setBoat (this=0x555556f9d900, direction=256, color=2) at /home/rgo/src/fheroes2/src/fheroes2/maps/maps_tiles.cpp:617
#6  0x00005555555d2e21 in (anonymous namespace)::AIToCoast (hero=..., dst_index=2210) at /home/rgo/src/fheroes2/src/fheroes2/ai/ai_hero_action.cpp:1628
#7  0x00005555555d3ce1 in AI::HeroesAction (hero=..., dst_index=2210) at /home/rgo/src/fheroes2/src/fheroes2/ai/ai_hero_action.cpp:1746
#8  0x0000555555928c19 in Heroes::Action (this=0x555556d8df50, tileIndex=2210) at /home/rgo/src/fheroes2/src/fheroes2/heroes/heroes_action.cpp:3613
#9  0x0000555555938f76 in operator() (__closure=0x7fffffffd100, performMovement=true) at /home/rgo/src/fheroes2/src/fheroes2/heroes/heroes_move.cpp:240
#10 0x0000555555939186 in Heroes::MoveStep (this=0x555556d8df50, jumpToNextTile=false) at /home/rgo/src/fheroes2/src/fheroes2/heroes/heroes_move.cpp:279
#11 0x000055555593a10e in Heroes::Move (this=0x555556d8df50, jumpToNextTile=false) at /home/rgo/src/fheroes2/src/fheroes2/heroes/heroes_move.cpp:580
#12 0x00005555555d46be in AI::HeroesMove (hero=...) at /home/rgo/src/fheroes2/src/fheroes2/ai/ai_hero_action.cpp:2099
#13 0x00005555556099b5 in AI::Normal::HeroesTurn (this=0x555555cb1760 <AI::Get(AI::AI_TYPE)::normal>, heroes=..., startProgressValue=1, endProgressValue=8)
    at /home/rgo/src/fheroes2/src/fheroes2/ai/normal/ai_normal_hero.cpp:2714
#14 0x0000555555617447 in AI::Normal::KingdomTurn (this=0x555555cb1760 <AI::Get(AI::AI_TYPE)::normal>, kingdom=...) at /home/rgo/src/fheroes2/src/fheroes2/ai/normal/ai_normal_kingdom.cpp:861
#15 0x000055555583582d in Interface::AdventureMap::StartGame (this=0x555555cb3a00 <Interface::AdventureMap::Get()::basic>) at /home/rgo/src/fheroes2/src/fheroes2/game/game_startgame.cpp:875
#16 0x0000555555832a3f in Game::StartGame () at /home/rgo/src/fheroes2/src/fheroes2/game/game_startgame.cpp:171
#17 0x0000555555822dc0 in Game::mainGameLoop (isFirstGameRun=false) at /home/rgo/src/fheroes2/src/fheroes2/game/game_mainmenu.cpp:169
#18 0x00005555557ec687 in main (argc=1, argv=0x7fffffffdac8) at /home/rgo/src/fheroes2/src/fheroes2/game/fheroes2.cpp:328
(gdb) quit
@kuuff kuuff added the bug Something doesn't work label Feb 29, 2024
@oleg-derevenetz
Copy link
Collaborator

oleg-derevenetz commented Feb 29, 2024

Yeah, it's very interesting bug. I'm not very familiar with the hero movement animation logic in AI::HeroesMove(), but it seems that in this case it advances the hero's sprite_index too much, and it causes extra movement in the Heroes::MoveStep() method which normally shouldn't happen (because MP2::OBJ_COAST for the hero on the water is an object that needs to be interacted with while being next to it, not on it). sprite_index eventually becomes 17 before the last step, which causes makeStep( true ) to be ultimately called at line 279 here:

const int currentHeroFrameIndex = ( sprite_index % heroFrameCountPerTile );
if ( currentHeroFrameIndex == 0 ) {
if ( isNeedStayFrontObject( *this, world.GetTiles( nextStepIndex ) ) ) {
makeStep( false );
return true;
}
if ( GetKingdom().isControlHuman() ) {
const fheroes2::Point & mp = GetCenter();
playHeroWalkingSound( world.GetTiles( mp.x, mp.y ).GetGround() );
}
}
else if ( currentHeroFrameIndex == 1 ) {
// This is a start of hero's movement. We should clear fog around him.
Scout( nextStepIndex );
}
else if ( currentHeroFrameIndex == 8 ) {
sprite_index -= 8;
makeStep( true );
// if we continue to move into the same direction we must skip first frame as it's for stand position only
if ( isMoveEnabled() && GetDirection() == path.GetFrontDirection() && !isNeedStayFrontObject( *this, world.GetTiles( path.GetFrontIndex() ) ) ) {
if ( GetKingdom().isControlHuman() ) {
playHeroWalkingSound( world.GetTiles( heroIndex ).GetGround() );
}
++sprite_index;
}
return true;
}

which normally shouldn't be, because currentHeroFrameIndex should become 0 before accessing objects that need to be interacted with while being next to them (i.e. hero should be in "standing" state near these objects) - in this case isNeedStayFrontObject() check at line 260 should do its job and hero will interact with the coast object properly. This is how this looks like (in the step-by-step mode):

fheroes2.engine.version_.1.0.12.2024-02-29.22-28-30.mp4

Hi @ihhub since I am not very familiar with the implementation of the animation for the AI-controlled heroes, are there any tips on how to fix this in the "right" way? Can this happen to human-controlled heroes under some circumstances? Could you please take a look as soon as you have time for that?

@oleg-derevenetz oleg-derevenetz added the crash Application crashes. The highest level of priority label Feb 29, 2024
@oleg-derevenetz oleg-derevenetz added this to the 1.1.0 milestone Feb 29, 2024
@ihhub ihhub added the high priority Very critical change needed immediately label Mar 1, 2024
@ihhub ihhub self-assigned this Mar 1, 2024
@ihhub
Copy link
Owner

ihhub commented Mar 1, 2024

Sure. I will take a look.

@ihhub
Copy link
Owner

ihhub commented Mar 4, 2024

Hi @kuuff , can you try a build from #8450 ?

@kuuff
Copy link
Author

kuuff commented Mar 4, 2024

@ihhub, yeah, I tried, it fixes the issue, it doesn't crash. Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something doesn't work crash Application crashes. The highest level of priority high priority Very critical change needed immediately
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants