CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.61k stars 4.17k forks source link

Segmentation fault when closing the game #51581

Closed eltank closed 3 years ago

eltank commented 3 years ago

Describe the bug

When closing the game with either Alt-F4 or Q from the main menu, I sometimes see "Segmentation fault" in the console used to start the game.

Steps To Reproduce

  1. Start the game
  2. Load a save
  3. Quit the game

Expected behavior

No segfaults

Screenshots

No response

Versions and configuration

Additional context

I managed to get a stack trace by running under gdb. No line numbers because it's not a debug build.

Thread 1 received signal SIGSEGV, Segmentation fault.
0x00007ffdadc4222c in ?? () from D:\msys64\mingw64\bin\SDL2.dll
(gdb) bt
#0  0x00007ffdadc4222c in ?? () from D:\msys64\mingw64\bin\SDL2.dll
#1  0x00007ff7a717076d in std::_Sp_counted_deleter<SDL_Texture*, SDL_Texture_deleter, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_dispose() ()
#2  0x00007ff7a715b105 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() ()
#3  0x00007ff7a71beb83 in std::vector<texture, std::allocator<texture> >::~vector() ()
#4  0x00007ff7a65cc1cc in std::default_delete<tileset>::operator()(tileset*) const [clone .part.0] ()
#5  0x00007ff7a7131cd6 in std::unique_ptr<cata_tiles, std::default_delete<cata_tiles> >::~unique_ptr() ()
#6  0x00007ffdf0cfa73b in msvcrt!_initterm_e ()
   from C:\Windows\System32\msvcrt.dll
#7  0x00007ff7a6d351ef in CheckMessages() ()
#8  0x00007ff7a6d35376 in input_manager::get_input_event(keyboard_mode) ()
#9  0x00007ff7a68301b4 in input_context::handle_input[abi:cxx11](int) ()
#10 0x00007ff7a676f7ca in game::handle_mouseview(input_context&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) ()
#11 0x00007ff7a67d285f in game::get_player_input(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) ()
#12 0x00007ff7a67de955 in game::handle_action() ()
#13 0x00007ff7a66e7195 in do_turn() ()
#14 0x00007ff7a73cfcb3 in main ()

I also saw this in the console output before the segfault, may be related:

warning: avcore\audiocore\client\audioclient\audioclientcore.cpp(1856)\AUDIOSES.DLL!00007FFDEA807EF4: (caller: 00007FFDADCF5C91) ReturnHr(1) tid(25c0) 80070057 The parameter is incorrect.
eltank commented 3 years ago

Hmm, it seems to be happening while deallocating a vector<texture> from a tileset object.

ProfoundDarkness commented 3 years ago

huh... I'm seeing this on Windows but not on Linux (same CDDA version).

ProfoundDarkness commented 3 years ago

So I decided to do a bisect... firstly found that all that's needed is to load a game, minimal mods set. The key is to actually have the tiles load. Then once the game is loaded ALT-F4.

It would seem that da590d88 is the last good commit and 6adf8500 is the first bad one. Since tiles are modified and it's with tiles that the crash happens this at least makes some sense.

I don't know why I'd have different results on windows vs linux though I do have different configs with linux being far more out of the box default. I'm pretty much out of patience for now thanks to ccache refusing to use the directory I wanted (resolved) but I'll try to edit if I can spot cdda crashing on linux or not crashing on windows, if on linux with logs from debug compile.

--edit-- I didn't make any progress on the linux front though I did stumble on something interesting. The game only crashes (on windows) if set to windowbl mode. Maximized and fullscreen did NOT crash. I can't run windowbl on Linux so no testing on that (I know why, it's not cdda).

actual-nh commented 3 years ago

Ping: @KorGgenT?

KorGgenT commented 3 years ago

i have no idea.

eltank commented 3 years ago

If the working theory is that #50286 introduced the bug, I think this may be fixed now, by #51614. I also noticed another bug that was seemingly introduced by the former and fixed by the latter. I had an NPC that wasn't wielding anything and after updating my game past #50286, I got this:

image image

After updating past #51614 the NPC returned to normal. And when I exited the game I did not get a segfault.

ProfoundDarkness commented 3 years ago

Yep, no more crash on my end after updating cdda to version 0.F-2656-gf153adaee8.

--edit-- odd... just noticed that all of my mod_tilesets are being considered incompatible when the tileset's ID is listed in the compatibility section of the files. Out of curiosity I forced that tileset compatibility check to pass and the crash came back. This is probably a separate issue (the mod_tilesets errors certainly are)... point is the crash might be gone because something else broke. I still think it's apt this is closed, if more experienced people think so.

eltank commented 3 years ago

Ah, sorry I misunderstood the comment about which PR was identified as the culprit. The bug I described in my last comment is likely completely unrelated to this one. I was able to reproduce the segfault with a fairly recent build at a6634614a533ba3bad05768decff1c9119232844.

eltank commented 3 years ago

Another stack trace from a build at 8d47fe33cd72f8aadca39cf9e7fab74a6218717a obtained while I was debugging something else . It's basically the same as before, I was just in a different menu when I Alt-F4'd so the bottom half of the trace is different.

Thread 1 received signal SIGSEGV, Segmentation fault.
0x00007ffdadc4222c in ?? () from D:\msys64\mingw64\bin\SDL2.dll
(gdb) bt
#0  0x00007ffdadc4222c in ?? () from D:\msys64\mingw64\bin\SDL2.dll
#1  0x00007ff60e493aed in std::_Sp_counted_deleter<SDL_Texture*, SDL_Texture_deleter, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_dispose() ()
#2  0x00007ff60e47e485 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() ()
#3  0x00007ff60e4e1ee3 in std::vector<texture, std::allocator<texture> >::~vector() ()
#4  0x00007ff60d8ec04e in std::default_delete<tileset>::operator()(tileset*) const [clone .part.0] ()
#5  0x00007ff60e455146 in std::unique_ptr<cata_tiles, std::default_delete<cata_tiles> >::~unique_ptr() ()
#6  0x00007ffdf0cfa73b in msvcrt!_initterm_e ()
   from C:\Windows\System32\msvcrt.dll
#7  0x00007ff60e0544df in CheckMessages() ()
#8  0x00007ff60e054642 in input_manager::get_input_event(keyboard_mode) ()
#9  0x00007ff60db4e174 in input_context::handle_input[abi:cxx11](int) ()
#10 0x00007ff60db5bb42 in inventory_selector::get_input() ()
#11 0x00007ff60db65653 in inventory_pick_selector::execute() ()
#12 0x00007ff60dacd6bf in inv_internal(Character&, inventory_selector_preset const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, item_location) ()
#13 0x00007ff60dad1ac7 in game_menus::inv::repair(Character&, repair_item_actor const*, item const*) ()
#14 0x00007ff60d843b35 in activity_handlers::repair_item_finish(player_activity*, Character*) ()
#15 0x00007ff60e421917 in std::function<void (player_activity*, Character*)>::operator()(player_activity*, Character*) const ()
#16 0x00007ff60d85beb9 in activity_type::call_finish(player_activity*, Character*) const ()
#17 0x00007ff60df7dff6 in player_activity::do_turn(Character&) ()
#18 0x00007ff60da06258 in do_turn() ()
#19 0x00007ff60e6f3635 in main ()
anothersimulacrum commented 3 years ago

https://github.com/cataclysmbnteam/Cataclysm-BN/pull/259