Try / OpenGothic

Reimplementation of Gothic 2 Notr
MIT License
1.16k stars 82 forks source link

Crash on save at game beginning on Linux #664

Closed YALdysse closed 2 months ago

YALdysse commented 2 months ago

Describe the bug If you save the game at the beginning of the game after talking to Xardas, the game will crash. Always. The size of the save file will be 0 bytes.

OS: Linux Mint 21.3 OpenGothic version: v1.0.2836 (374e3ecc)

Version v1.0.2733 (commit ccdb92f9) did not have this problem.

Please, help.

Application log If relevant attach log.txt file or, in case of game-crash, crash.log crash.log log.txt

YALdysse commented 2 months ago

I've checked that version v1.0.2769 doesn't crash during saving. But version v1.0.2774 already has this problem. I believe that a mistake was made in the commit d5ece372.

Try commented 2 months ago

Hi, @YALdysse !

I've checked this case today on latest master - can't reproduce the issue. Also offended commit is d5ece372 is update for engine, that includes sound and graphics changes - very unlikely that it can affect save-load in the game.

In crash.log there is only one stack, from UI-thread and it eds with Tempest::EventDispatcher::dispatchKeyDown. Maybe it would be possible to reproduce this issue on your end in gdb, so we may have more information about what has crashed?

YALdysse commented 2 months ago

@Try, It will not be easy for me. I don't know how to use gdb.

Try commented 2 months ago

Assuming that you build a game by your self, in debug-build. To run you need to use gdb --args, followed by command line arguments, that you normally using. Example:

gdb --args ./Gothic2Notr -g "/path/to/gothic2"

Once crash occur, in gdb type bt command to see back-trace

YALdysse commented 2 months ago

I use build form AppVeyor. When I run the gdb command, nothing happens:

yaroslav@mYAL-PC:/media/yaroslav/mFreedom/4. Other/Games_installers/OpenGothic/game_v1.0.2837$ gdb --args ./Assets-Gothic_2/Gothic2Notr -g "./Assets-Gothic_2/" GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1 Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: https://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/.

For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./Assets-Gothic_2/Gothic2Notr...

(gdb) (gdb) (gdb)

YALdysse commented 2 months ago

I can't build the project myself because an error appears during the build process.

Try commented 2 months ago

I use build form AppVeyor. When I run the gdb command, nothing happens:

Ah, right.., you probably need to type r (run application) - sorry, forgot how exactly use gdb from command-line

thokkat commented 2 months ago

Debug log:

1  __gnu_cxx::__exchange_and_add                                                                      atomicity.h         66   0x5555560c6122 
2  __gnu_cxx::__exchange_and_add_dispatch                                                             atomicity.h         101  0x5555560c6122 
3  std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_weak_release                                 shared_ptr_base.h   212  0x5555560c6122 
4  std::__weak_count<(__gnu_cxx::_Lock_policy)2>::operator=                                           shared_ptr_base.h   1178 0x5555560c5669 
5  std::__weak_ptr<Tempest::Widget::Ref, (__gnu_cxx::_Lock_policy)2>::operator=<Tempest::Widget::Ref> shared_ptr_base.h   2049 0x7ffff7a42a91 
6  std::weak_ptr<Tempest::Widget::Ref>::operator=<Tempest::Widget::Ref>                               shared_ptr.h        857  0x7ffff7a41ef5 
7  Tempest::EventDispatcher::dispatchKeyDown                                                          eventdispatcher.cpp 171  0x7ffff7a3fbf7 
8  Tempest::SystemApi::dispatchKeyDown                                                                systemapi.cpp       137  0x7ffff7a460f6 
9  Tempest::X11Api::implProcessEvents                                                                 x11api.cpp          523  0x7ffff7a376e8 
10 Tempest::X11Api::implExec                                                                          x11api.cpp          400  0x7ffff7a36ed3 
11 Tempest::SystemApi::exec                                                                           systemapi.cpp       178  0x7ffff7a462bd 
12 Tempest::Application::exec                                                                         application.cpp     111  0x7ffff7a3c451 
13 main                                                                                               main.cpp            145  0x555555f962e4 

In rare cases it's crashing with dev being null in ~Impl instead the above.

1  std::__uniq_ptr_impl<Tempest::SoundDevice::Data, std::default_delete<Tempest::SoundDevice::Data>>::_M_ptr unique_ptr.h    193  0x7ffff7a32572 
2  std::unique_ptr<Tempest::SoundDevice::Data, std::default_delete<Tempest::SoundDevice::Data>>::get         unique_ptr.h    464  0x7ffff7a32084 
3  std::unique_ptr<Tempest::SoundDevice::Data, std::default_delete<Tempest::SoundDevice::Data>>::operator->  unique_ptr.h    457  0x7ffff7a3201a 
4  Tempest::SoundDevice::context                                                                             sounddevice.cpp 250  0x7ffff7a31638 
5  Tempest::SoundEffect::Impl::~Impl                                                                         soundeffect.cpp 64   0x7ffff7a34f46 
6  std::default_delete<Tempest::SoundEffect::Impl>::operator()                                               unique_ptr.h    93   0x7ffff7a356c0 
7  std::unique_ptr<Tempest::SoundEffect::Impl, std::default_delete<Tempest::SoundEffect::Impl>>::~unique_ptr unique_ptr.h    398  0x7ffff7a35424 
8  Tempest::SoundEffect::~SoundEffect                                                                        soundeffect.cpp 119  0x7ffff7a3424a 
9  DialogMenu::close                                                                                         dialogmenu.cpp  346  0x555555ffc613 
10 DialogMenu::onWorldChanged                                                                                dialogmenu.cpp  164  0x555555ffb799 
11 MainWindow::onWorldLoaded                                                                                 mainwindow.cpp  1062 0x555555f9ed33 
12 Tempest::Signal<void()>::TImpl<MainWindow, MainWindow, void>::call                                        tempestsignal.h 136  0x555555fa57ca 
13 Tempest::Signal<void()>::Impl::call                                                                       tempestsignal.h 91   0x555555e62245 
14 Tempest::Signal<void()>::operator()                                                                       tempestsignal.h 70   0x555555e60389 
15 Gothic::finishLoading                                                                                     gothic.cpp      461  0x555555e95eb4 
YALdysse commented 2 months ago

@thokkat, Thank you for the log. I couldn't make it yesterday.

Try commented 2 months ago

@thokkat thanks for the log!

how do you reproduce this: do you use quick save or main-menu -> save-game ?

thokkat commented 2 months ago

Normal saving in menu. I think quick save never crashed. Basically starting a new game and keep saving until crash.

YALdysse commented 2 months ago

I think quick save never crashed.

Amazing, quick save/load work correctly. @thokkat was right.

Try commented 2 months ago

For the record: can't reproduce it on my windows machine, even by saving rapidly non-stop.

After careful read of offended part of code, my theory is that, pointer to keyUp was corrupted by recursion:

void EventDispatcher::dispatchKeyDown(Widget &wnd, KeyEvent &e, uint32_t scancode) {
  auto& k = keyUp[scancode]; // invalidates same "k", in stack-frame above

Please, test, if fix works for you

YALdysse commented 2 months ago

@Try, it's amazing. It works. Thank you so much for continuing to develop OpenGothic. In my opinion, the issue can be closed.