SDL-2.0.4 / SDL_WindowFrom / SDL_CreateRenderer() Hanging

Hello everyone

Operating System: Linux (Fedora 24)
wxWidgets: 3.1.0 compiled against GTK3


I’m having a problem trying to embed SDL2 into wxWidgets using SDL_WindowFrom(win->GetHandle()). I have tried this using Qt5 so it’s not specifically a wxWidgets problem. My tests show that SDL_CreateWindowFrom() is working fine. However, when I try to setup a SDL_CreateRenderer(sdl_window, -1, SDL_RENDERER_ACCELERATED) I find that the function never returns. I have done a great deal of Googling and found lots of posts related to this problem. Some of these posts recommend patching src/video/x11/SDL_x11window.c which I have tried but to no avail.

I have tried using SDL_RENDERER_SOFTWARE but this just segfaults at vinfo->visualid = X11_XVisualIDFromVisual(visual); in SDL_x11modes.c

I have also tried compiling wxWidgets against gtk2 instead of gtk3. When I do this II get a Gdk-ERROR ‘BadWindow’ from SDL_CreateWindowFrom()

Further digging around has lead me to believe that I may need to set the SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT flag but I am not sure how to set this flag. Can anybody offer any advice or point me towards a some example code?

Please see the following code example which hopefully will show you what I have tried to date. PS: My SDL2 install workers perfectly in a stand-alone mode.

I hope somebody can help and I thank you for taking time to read my post.



wxPanel *panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(800, 600), wxTAB_TRAVERSAL);

SDL_Window *sdl_window = SDL_CreateWindowFrom((void*) panel->GetHandle());

if (sdl_window == NULL) {
    std::cerr << SDL_GetError();

SDL_Renderer* r = SDL_CreateRenderer(sdl_window, -1, SDL_RENDERER_ACCELERATED); // Hangs Here!

if (r == NULL) {
    std::cerr << SDL_GetError();

SDL_SetRenderDrawColor(r, 255, 0, 0, 255);
SDL_RenderFillRect(r, NULL);

sizer->Add(panel, 1, wxALL | wxEXPAND, 5);
this->SetSize(900, 700);


Is there anybody that can offer help with my problem?

Kind Regards

I am desperate to get this problem solved but if my question is silly, rather than ignoring me, please let me know so that I can rephrase my question. This is my second post with regards to this problem but despite hundreds of views there has been no reply. I fully understand that respondents are volunteers and appreciate any offer of help.

I would be grateful to hear from any body that could offer even the slightest insight into this issue.

I have recompiled wxWidgets 3.1 against GTK-2 but making a call to: SDL_Window sdl_window = SDL_CreateWindowFrom((void) panel->GetHandle()); causes the following message:

: Gdk-ERROR **: The program ‘program name’ received an X Window System error.
This probably reflects a bug in the program.
The error was ‘BadWindow (invalid Window parameter)’.
(Details: serial 138 error_code 3 request_code 20 minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)

RUN FINISHED; Trace/breakpoint trap; core dumped; real time: 700ms; user: 20ms; system: 70ms

When compiled against GTK3 the above error goes away but SDL_CreateRenderer(window, -1, SD_RENDERER_ACCELERATED) never returns. I.E. It seems to hang…

Many thanks

I am not using SDL2 on Linux at the moment but I searched for what wxWidget::GetHandle() possibly does, and it looks like it doesn’t return any “window” pointer, but perhaps a GtkWidget pointer. If this is true you may need to find out a way to get that window pointer.

Dear Capehill

I cannot thank you enough.

I was assuming (a rather silly thing to do) that ::GetHandler() was returning a native XID. It wasn’t. For the benefit of anybody else trying to embed SDL2 into wxWidgets here is my example code.


GtkWidget* widget = panel->GetHandle();
Window XID = GDK_WINDOW_XWINDOW(widget->window);

SDL_Window *sdl_window = SDL_CreateWindowFrom((void*) XID);

if (sdl_window == NULL)
    std::cerr << SDL_GetError();

SDL_Renderer* r = SDL_CreateRenderer(sdl_window, -1, SDL_RENDERER_SOFTWARE);

if (r == NULL)
    std::cerr << SDL_GetError();

And then, in a separate thread loop with the usual SDL_Renderer functions


while (true)
SDL_SetRenderDrawColor(r, 255, 0, 255, 255);

Once again, thank you Capehill :slight_smile: