Zandronum Chat on our Discord Server Get the latest version: 3.2
Source Code

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004023Zandronum[All Projects] Bugpublic2022-09-02 04:072024-11-05 12:33
Reportericculus 
Assigned ToDrinkyBird 
PrioritynormalSeveritycrashReproducibilityalways
StatusresolvedResolutionfixed 
PlatformLinuxOSUbuntuOS Version10.04 x86-64
Product Version3.1 
Target Version3.2Fixed in Version3.2 
Summary0004023: SDL_Init must be called before gtk_init_check
DescriptionOn platforms using X11, the latest SDL 1.2 from'https://github.com/libsdl-org/SDL-1.2 [^]' will call XInitThreads() during SDL_Init. If XInitThreads is called at all, it has to be the first function called in Xlib.

If showing the IWAD selector, Zandronum will call gtk_init_check() before SDL_Init, to decide if it should show a GTK+ dialog or try a simple stdio interface instead. But in doing so, GTK+ will initialize Xlib in various ways without thread safety. When SDL_Init is later called, calling XInitThreads, Xlib will then expect mutexes to be available for things GTK+ has already initialized without them, and the end result is a crash.

Most Linux distros are not shipping an SDL-1.2 build that calls XInitThreads yet, but many are switching over to sdl12-compat to replace SDL-1.2, and this will definitely call XInitThreads.

This crash is avoided if there's only one IWAD file (you have Doom 1's data but not Doom 2's, etc), since the GTK code is not used.

Technical details are listed at sdl12-compat's bug tracker, where we tracked this down:

'https://github.com/libsdl-org/sdl12-compat/issues/200 [^]'

Since this is an X11 thing, running the game on Wayland with sdl12-compat completely avoids X11 and does not crash this way.
Steps To Reproduce- Install the latest SDL-1.2 or sdl12-compat on a Linux machine running X11.
- Install Zandronum
- Install at least two IWAD files.
- Run Zandronum
- Watch it crash while half-creating the IWAD GTK+ selector.

Additional InformationThe fix is simple, just call SDL_Init before gtk_init_check:

diff -r b460d88f3a9e src/sdl/i_main.cpp
--- a/src/sdl/i_main.cpp Sun Aug 28 16:13:35 2022 -0400
+++ b/src/sdl/i_main.cpp Thu Sep 01 23:28:05 2022 -0400
@@ -263,10 +263,6 @@
        // Note that the LANG environment variable is overridden by LC_*
        setenv ("LC_NUMERIC", "C", 1);
 
-#ifndef NO_GTK
- GtkAvailable = gtk_init_check (&argc, &argv);
-#endif
-
        setlocale (LC_ALL, "C");
 
        Args = new DArgs(argc, argv);
@@ -302,6 +298,13 @@
 
        atterm (SDL_Quit);
 
+ // Make sure gtk_init_check happens _after_ SDL_Init, so SDL will call
+ // XInitThreads() on X11, then GTK+ will talk to Xlib without leaving
+ // mutexes uncreated that the system is going to expect to be initialized.
+#ifndef NO_GTK
+ GtkAvailable = gtk_init_check (&argc, &argv);
+#endif
+
        {
                char viddriver[80];
 
Attached Files

- Relationships

-  Notes
User avatar (0022331)
DrinkyBird (developer)
2022-09-03 22:06

Pleasant surprise to see icculus himself here! We were looking into using sdl1.2-compat on macOS and Linux, so this report and patch is timely and very much appreciated; I'll bring it up during our next dev meeting.

Of course the ideal solution would be to use SDL2 directly, but unfortunately we've got ourselves pinned against a very old version of GZDoom that still uses SDL1.2, and we don't like to make large selective backports as it can make general updates from upstream harder...
User avatar (0022332)
doomjoshuaboy (developer)
2022-09-04 07:38
edited on: 2022-09-04 07:39

Yeah thanks so much icculus sdl12-compat and SDL2 will be required as a framework on the MacOS as I already tested it in a m1 CPU with Rosetta 2 and it works out really well.

User avatar (0022333)
Torr Samaho (administrator)
2022-09-04 20:12

Thanks! I added the patch.
User avatar (0022335)
WubTheCaptain (reporter)
2022-09-05 00:22

Commit: a079616e5796d1300945766df2776605a1dbd771 - zandronum-stable (hg)
User avatar (0022350)
icculus (reporter)
2022-09-06 04:04

You all are awesome, I really appreciate both the fast response and the kind words. :)

Thank you!
User avatar (0024118)
DrinkyBird (developer)
2024-11-05 12:33

I went to test this today and was unable to get 3.1 to crash when opening the IWAD picker under X11; using sdl12_compat-1.2.68-1.14 from openSUSE Tumbleweed. It has been two years (oh my) since this issue was filed so there's a chance something in the stack has changed since then...

3.2 also doesn't crash though, so I guess I can mark this as fixed.

Issue Community Support
This issue is already marked as resolved.
If you feel that is not the case, please reopen it and explain why.
Supporters: No one explicitly supports this issue yet.
Opponents: No one explicitly opposes this issue yet.

- Issue History
Date Modified Username Field Change
2022-09-02 04:07 icculus New Issue
2022-09-03 22:06 DrinkyBird Note Added: 0022331
2022-09-04 07:38 doomjoshuaboy Note Added: 0022332
2022-09-04 07:39 doomjoshuaboy Note Edited: 0022332 View Revisions
2022-09-04 20:12 Torr Samaho Note Added: 0022333
2022-09-04 20:13 Torr Samaho Status new => needs testing
2022-09-04 20:50 DrinkyBird Target Version => 3.2
2022-09-05 00:22 WubTheCaptain Note Added: 0022335
2022-09-06 04:04 icculus Note Added: 0022350
2024-11-05 12:33 DrinkyBird Note Added: 0024118
2024-11-05 12:33 DrinkyBird Status needs testing => resolved
2024-11-05 12:33 DrinkyBird Fixed in Version => 3.2
2024-11-05 12:33 DrinkyBird Resolution open => fixed
2024-11-05 12:33 DrinkyBird Assigned To => DrinkyBird






Questions or other issues? Contact Us.

Links


Copyright © 2000 - 2025 MantisBT Team
Powered by Mantis Bugtracker