We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 748

Summary: creating a window segfaults if gtk inited before SDL (1.3)
Product: SDL Reporter: Gerry JJ <trick>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: jspradlin
Version: HG 2.0   
Hardware: x86   
OS: Linux   
Attachments: segfault example

Description Gerry JJ 2009-06-04 20:25:37 UTC
Created attachment 328 [details]
segfault example

Current SDL 1.3 svn segfaults (inside X) if these functions are called in this order:

1. gtk_init (or gtk_init_check, etc)
2. SDL_Init(SDL_INIT_VIDEO) (or SDL_VideoInit)
3. SDL_SetVideoMode (or SDL_CreateWindow) <- segfault

In SDL 1.2, there's no segfault and SetVideoMode succeeds.  Also, it works fine in 1.3 too if SDL_Init is moved to before gtk_init:

1. SDL_Init(SDL_INIT_VIDEO)
2. gtk_init
3. SDL_SetVideoMode <- segfault

Attached an example.  Also, here's a gdb backtrace of that with SDL 1.3 and gtk inited before SDL:

(gdb) bt
#0  0x00007f615aa8f22e in XCreateIC () from /usr/lib/libX11.so.6
#1  0x00007f615ea9afbc in SetupWindowData (_this=0x24fa8a0, window=0x7fff66ef82f0, w=79691778, created=1 '\001')
    at ../SDL-1.3/src/video/x11/SDL_x11window.c:82
#2  0x00007f615ea9c59e in X11_CreateWindow (_this=0x24fa8a0, window=0x7fff66ef82f0) at ../SDL-1.3/src/video/x11/SDL_x11window.c:690
#3  0x00007f615ea83100 in SDL_CreateWindow (title=0x0, x=134217727, y=134217727, w=320, h=240, flags=4) at ../SDL-1.3/src/video/SDL_video.c:790
#4  0x00007f615e9d5463 in SDL_SetVideoMode (width=320, height=240, bpp=0, flags=0) at ../SDL-1.3/src/SDL_compat.c:556
#5  0x0000000000400a61 in main ()

This is on Arch Linux, 64-bit, with SDL 1.3 rev 4529 and gtk 2.16.2, xorg-server 1.6.1.901
Comment 1 Gerry JJ 2009-06-04 20:29:04 UTC
Oops .. the "segfaults" in that second list should be "works":

1. SDL_Init(SDL_INIT_VIDEO)
2. gtk_init
3. SDL_SetVideoMode <- works!
Comment 2 Sam Lantinga 2010-07-17 23:45:52 UTC
I just tried this on Ubuntu 10.04 with and without SDL_BEFORE_GTK defined and I got "creating window... success!" output both times.

Are you still getting this error with the latest SDL snapshot?
http://www.libsdl.org/tmp/SDL-1.3.zip
Comment 3 Gerry JJ 2010-07-18 09:38:15 UTC
(In reply to comment #2)
> Are you still getting this error with the latest SDL snapshot?
> http://www.libsdl.org/tmp/SDL-1.3.zip

Yes, it's segfaulting in the same place when SDL_BEFORE_GTK is undefined, but works when SDL_BEFORE_GTK is defined, as before.  Still Arch 64-bit, gtk now at 2.20.1-2 and xorg-server at 1.8.1.902-1. Standard Arch packages, not using anything custom there.
Comment 4 Sam Lantinga 2013-05-21 01:07:26 UTC
I believe this is fixed in the latest snapshot:
http://www.libsdl.org/tmp/SDL-2.0.zip

This was related to X locale support.

Please reopen this bug for SDL 2.1 if it's still active.

Thanks!