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 4332

Summary: SDL_WINDOW_FULLSCREEN window disappears upon first call to SDL_PumpEvents, workaround provided
Product: SDL Reporter: Elmar <elmar>
Component: eventsAssignee: Ryan C. Gordon <icculus>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.9   
Hardware: x86_64   
OS: Linux   

Description Elmar 2018-10-26 07:35:57 UTC
Dear all,

I'm migrating my app from SDL1 to SDL2. Using the latest 2.0.9 nightly snapshot, my app disappears as soon as it goes fullscreen, this happens in CentOS 6 (KDE), CentOS 7 (KDE) and Ubuntu 18.04 (default desktop), while Windows and MacOS are fine.

After a lot of debugging, I found the following:
Having created the fullscreen window, upon calling SDL_PumpEvents, the function X11_DispatchEvent receives a FocusOut event. It calls X11_DispatchFocusOut, which calls SDL_SetKeyboardFocus(NULL), which calls SDL_SendWindowEvent(SDL_WINDOWEVENT_FOCUS_LOST), which calls  SDL_OnWindowFocusLost(window), which checks ShouldMinimizeOnFocusLoss and finally calls SDL_MinimizeWindow(window) - and my app is gone.

The "workaround" is to fudge ShouldMinimizeOnFocusLoss with
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,"0");

Obviously, there are zillions of SDL2 Linux apps that use fullscreen happily, so the issue must somehow be caused by my app. Unfortunately I didn't have the time to investigate why the X-server sends a nasty FocusOut event in the first place,  but maybe this story rings a bell for some of you.

This could be a duplicate of this old bug report:
https://bugzilla.libsdl.org/show_bug.cgi?id=2642

Best regards,
Elmar
Comment 1 Sam Lantinga 2018-10-28 21:18:51 UTC
Ryan, can you look to see if this is a regression in SDL 2.0.9?

Thanks!
Comment 2 Elmar 2018-10-28 22:14:36 UTC
(In reply to Sam Lantinga from comment #1)
> Ryan, can you look to see if this is a regression in SDL 2.0.9?
> 
> Thanks!

I initially had the problem with SDL 2.0.8, and then updated to the latest 2.0.9 devsnapshot to check that it's still there before filing this report.
Comment 3 Ryan C. Gordon 2018-10-28 23:28:34 UTC
Checking tonight.

—ryan.
Comment 4 Ryan C. Gordon 2018-10-30 04:03:57 UTC

This isn’t reproducing for me; is your source code available somewhere that I can see (even if it’s just the piece that creates the window and pumps events)?

Or even a very small example C program that just creates a window and triggers this bug?

--ryan.

I’m
Comment 5 Elmar 2018-10-30 07:35:32 UTC
Getting a small example program will be many hours of work. But since you guys are doing such a great job, I spent the first hour to get closer to the source of the problem.

I found the following:

- Create Window:
vga_window=SDL_CreateWindow("MyTitle",0,0,1280,1024,0x2007);

- Create OpenGL context with shader initialization etc.

- SDL_PumpEvents();

- for (i=0;i<10;i++) SDL_GL_SwapWindow(vga_window);

- SDL_PumpEvents();

The above recipe works fine. BUT if I delete the first SDL_PumpEvents, the window disappears.

Conclusion: I have to call SDL_PumpEvents *before* the first call to SDL_GL_SwapWindow.

This is reproducible on three different Linux PCs, two with NVIDIA proprietary drivers, one with AMD fglrx driver.

Does this help?

Best regards,
Elmar