gemrb / gemrb

GemRB is a portable open-source implementation of Bioware’s Infinity Engine.
https://gemrb.org
GNU General Public License v2.0
983 stars 184 forks source link

IWD2 CREImporter segfault #2195

Closed MarcelHB closed 3 weeks ago

MarcelHB commented 4 weeks ago

Bug description

It just started to happen now. I didn't do any updates to the wizard's spellbook.

Screenshots

(gdb) bt
#0  0x00007ffc3ec9a4bc in std::_Hashtable<unsigned int, std::pair<unsigned int const, unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int> >, std::__detail::_Select1st, std::equal_to<unsigned int>, std::hash<unsigned in
t>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::size (this=0x387469f94fb7a2ab)
    at C:/MSYS2/mingw64/include/c++/14.2.0/bits/hashtable.h:657
#1  0x00007ffc3ec9a3cf in std::_Hashtable<unsigned int, std::pair<unsigned int const, unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int> >, std::__detail::_Select1st, std::equal_to<unsigned int>, std::hash<unsigned in
t>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::find (this=0x387469f94fb7a2ab, __k=@0x5fdfb0: 8)
    at C:/MSYS2/mingw64/include/c++/14.2.0/bits/hashtable.h:1751
#2  0x00007ffc3ec9a800 in std::unordered_map<unsigned int, unsigned int, std::hash<unsigned int>, std::equal_to<unsigned int>, std::allocator<std::pair<unsigned int const, unsigned int> > >::find (this=0x387469f94fb7a2ab, __x=@0x5fdfb0: 8)
    at C:/MSYS2/mingw64/include/c++/14.2.0/bits/unordered_map.h:888
#3  0x00007ffc3ec613c1 in SpellEntry::FindSpell (this=0x387469f94fb7a29b, level=0, kit=8) at D:/Sources/gemrb/gemrb/plugins/CREImporter/CREImporter.cpp:67
#4  0x00007ffc3ec61e65 in ResolveSpellIndex (index=-1, level=0, type=GemRB::IE_IWD2_SPELL_WIZARD, kit=8) at D:/Sources/gemrb/gemrb/plugins/CREImporter/CREImporter.cpp:309
#5  0x00007ffc3ec680d5 in GemRB::CREImporter::GetIWD2Spellpage (this=0x241697b0, act=0x2419bf80, type=GemRB::IE_IWD2_SPELL_WIZARD, level=0, count=10) at D:/Sources/gemrb/gemrb/plugins/CREImporter/CREImporter.cpp:1397
#6  0x00007ffc3ec69e6a in GemRB::CREImporter::GetActorIWD2 (this=0x241697b0, act=0x2419bf80) at D:/Sources/gemrb/gemrb/plugins/CREImporter/CREImporter.cpp:1644
#7  0x00007ffc3ec64b5f in GemRB::CREImporter::GetActor (this=0x241697b0, is_in_party=0 '\000') at D:/Sources/gemrb/gemrb/plugins/CREImporter/CREImporter.cpp:895
#8  0x00007ffc59e86551 in GemRB::AREImporter::GetActor (this=0x239ba430, str=0x23a56830, actorMgr=std::shared_ptr<GemRB::ActorMgr> (use count 2, weak count 0) = {...}, map=0x240f81f0)
    at D:/Sources/gemrb/gemrb/plugins/AREImporter/AREImporter.cpp:1135
#9  0x00007ffc59e88ccd in GemRB::AREImporter::GetMap (this=0x239ba430, resRef=..., day_or_night=true) at D:/Sources/gemrb/gemrb/plugins/AREImporter/AREImporter.cpp:1561
#10 0x00007ffc0a72a855 in GemRB::Game::LoadMap (this=0x20e93060, resRef=..., loadscreen=true) at D:/Sources/gemrb/gemrb/core/Game.cpp:851
#11 0x00007ffc0a729bda in GemRB::Game::GetMap (this=0x20e93060, areaName=..., change=true) at D:/Sources/gemrb/gemrb/core/Game.cpp:671
#12 0x00007ffc0a705426 in GemRB::GameControl::ChangeMap (this=0x20bd3940, pc=0x20f0ea30, forced=true) at D:/Sources/gemrb/gemrb/core/GUI/GameControl.cpp:2573
#13 0x00007ffc0a782d45 in GemRB::Interface::HandleFlags (this=0x5ff2a0) at D:/Sources/gemrb/gemrb/core/Interface.cpp:815
#14 0x00007ffc0a783ad8 in GemRB::Interface::Main (this=0x5ff2a0) at D:/Sources/gemrb/gemrb/core/Interface.cpp:983
#15 0x00007ff713c21647 in main (argc=1, argv=0x616450) at D:/Sources/gemrb/platforms/windows/GemRB.cpp:63

Problem is in frame 4, spellindex is read as -1, so likely written wrong during save, but not sure what has caused this.

GemRB version (check as many as you know apply)

lynxlynxlynx commented 4 weeks ago

I did make it a bit more robust recently, with one oops fixed yesterday, but maybe you were in some interim state when saving?

MarcelHB commented 4 weeks ago

Hard to say, I handled this case and probably just lost a spell or something. Will keep an eye on this.

MarcelHB commented 3 weeks ago

Could not reproduce any more, also after level up and new spells.