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.6k stars 365 forks source link

Segfault OS X Map 10 Price of Loyalty #3581

Closed mgtremaine closed 3 years ago

mgtremaine commented 3 years ago

I have Seg Fault on OS X in the Price of Loyalty Map 10... In the start of the game if Kalindra attacks Corlagon and lightning bolts the Champions the same segfault after the victory screen.

Attached is part of the backtrace. I'll try to see if other combos work around or also crash but I tried it 3 times to make sure.

sig_fault_osx-05312021.txt

-Mike

ihhub commented 3 years ago

Hi @mgtremaine , could you please provide a save file for this?

mgtremaine commented 3 years ago

In zip file.. homm2_crash_save.zip

oleg-derevenetz commented 3 years ago

A quick glance reveals that std::find() returns heroes.end() here (wasn't able to find such hero in a kingdom):

https://github.com/ihhub/fheroes2/blob/426d8cf9e7d78fe114f1eb34b7e880dab040f808/src/fheroes2/kingdom/kingdom.cpp#L274

so heroes.erase() crashes, because its argument isn't dereferenceable.

Purple kingdom at this moment have four heroes: Zam, Rialdo, Roxana and Sandro, but not Corlagon. It looks like Corlagon wasn't added to the purple kingdom in the beginning of this campaign episode for some reason.

oleg-derevenetz commented 3 years ago

hi @ihhub I have some suspicions regarding applyObtainedCampaignAwards() in game/game_campaign.cpp. In this function hero may be removed from kingdom if TYPE_DEFEAT_ENEMY_HERO award was received, but this hero may still be present on map itself. Is this possible?

ihhub commented 3 years ago

Hi @oleg-derevenetz , I have a fix for this. I'll create a pull request in the next 1-2 hours.