Cataclysm-DDA icon indicating copy to clipboard operation
Cataclysm-DDA copied to clipboard

Segfault on fresh start

Open risusinf opened this issue 1 year ago • 11 comments

Describe the bug

Freshly downloaded experimental crashes on launch

Attach save file

N/A

Steps to reproduce

  1. Download cdda-linux-tiles-x64-2024-08-19-0749.tar.gz
  2. Extract
  3. Change nothing, go straight for the launcher
  4. Segfault

Expected behavior

Game would launch.

Screenshots

No response

Versions and configuration

Void Linux, build x64-2024-08-19-0749, tiles Can't get to the main menu and didn't change anything manually prior to launch

Additional context

crash.log

PS. Before this had a build from last month, it works fine

risusinf avatar Aug 19 '24 08:08 risusinf

I can confirm this, crashes straight up on game start before anything is drawn. Looks imgui related based on the stack trace.

harakka avatar Aug 23 '24 06:08 harakka

I can confirm this, crashes straight up on game start before anything is drawn. Looks imgui related based on the stack trace.

Language selector is supposed to be shown on first launch, i assume it is managed by imgui now and doesn't work?

risusinf avatar Aug 23 '24 06:08 risusinf

Worked around this by copying the config dir from older build. The game doesn't crash if a language is already set.

strategictraveler avatar Aug 23 '24 12:08 strategictraveler

So IDK why, but just deleting the call to select_language() is enough to get through this issue and enter the main menu correctly. Something later must be initializing some kind of state that select_language depends on.

+++ b/src/main.cpp
@@ -851,8 +851,7 @@

 #if defined(LOCALIZE)
     if( get_option<std::string>( "USE_LANG" ).empty() && !SystemLocale::Language().has_value() ) {
-        const std::string lang = select_language();

akrieger avatar Aug 25 '24 01:08 akrieger

diff --git a/src/third-party/imgui/imgui.cpp b/src/third-party/imgui/imgui.cpp
--- a/src/third-party/imgui/imgui.cpp
+++ b/src/third-party/imgui/imgui.cpp
@@ -5093,6 +5093,9 @@
         text_display_end = text_end;

     ImFont* font = g.Font;
+    if (!font) {
+        font = GetDefaultFont();
+    }
     const float font_size = g.FontSize;
     if (text == text_display_end)
         return ImVec2(0.0f, font_size);

this is enough to stop the crash, but the language selection menu a) doesn't render until a keystroke is entered, and b) renders all fucky anyway. But I'm not testing on a fully up to date master so I need to recheck if that's still the case.

Font gets set in ImGui::NewFrame() to the result of GetDefaultFont(), but honestly if there isn't already a font chosen then the default isn't any worse than anything else.

akrieger avatar Aug 25 '24 02:08 akrieger

image

This is what I get after one keystroke with that diff. @db48x IDK if that's tracked in a separate issue or relevant to this particular codepath happening 'pre main menu'.

akrieger avatar Aug 25 '24 02:08 akrieger

Interestingly the tiles build actually renders the menu correctly. Screenshot 2024-08-24 at 9 33 29 PM

akrieger avatar Aug 25 '24 04:08 akrieger

diff --git a/src/third-party/imgui/imgui.cpp b/src/third-party/imgui/imgui.cpp
--- a/src/third-party/imgui/imgui.cpp
+++ b/src/third-party/imgui/imgui.cpp
@@ -5093,6 +5093,9 @@
         text_display_end = text_end;

     ImFont* font = g.Font;
+    if (!font) {
+        font = GetDefaultFont();
+    }
     const float font_size = g.FontSize;
     if (text == text_display_end)
         return ImVec2(0.0f, font_size);

this is enough to stop the crash

I wouldn’t make this change here in imgui.cpp. Instead, make sure that cataimgui::client::load_fonts is called early enough.

, but the language selection menu a) doesn't render until a keystroke is entered, and b) renders all fucky anyway. But I'm not testing on a fully up to date master so I need to recheck if that's still the case.

From your screenshot you are using ImTui, which either has problems or we’re using incorrectly. Or both! I haven’t looked into it yet, but I believe a separate bug has already been filed.

Oh, and two other people have mentioned that their menus also show up blank until they press a key or get the mouse involved, but I haven’t even been able to reproduce that.

db48x avatar Aug 25 '24 06:08 db48x

Yes, sorry. The messy menu was from imtui (I thought maybe the crash was im_gui_ related). But it happens in both builds. And it only renders okay in imgui.

I will play with reordering the fontloader call, thanks for that tip.

akrieger avatar Aug 26 '24 14:08 akrieger

I wouldn’t make this change here in imgui.cpp. Instead, make sure that cataimgui::client::load_fonts is called early enough.

So load_fonts is called in catacurses::init_interface(); which happens on line 781 https://github.com/CleverRaven/Cataclysm-DDA/blob/2db2a2ea1991860928044b75c8e1885d9b391ef2/src/main.cpp#L781. The crashing call to select_language is on line 854, which is well after that. So either the init call is happening too early (?) or something else is up.

akrieger avatar Aug 26 '24 22:08 akrieger

select_language doesn't crash if called after main_menu::opening_screen so clearly init_interface() isn't initting enough.

akrieger avatar Aug 26 '24 22:08 akrieger