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 1096

Summary: SDL_GLContext broken on windows that have not at least once been set visible
Product: SDL Reporter: Matthias <matthias.schweinoch>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: blocker    
Priority: P1 Keywords: target-2.0.0
Version: HG 2.0   
Hardware: x86_64   
OS: Linux   
Attachments: simple program to illustrate bug behavior
Possible fix

Description Matthias 2011-01-20 14:01:48 UTC
Please see attached file. 

The program should create a (hidden) window, create an opengl context, then clear the color buffer of that context, wait and exit.

Unless the created window is set visible at least once before calling SDL_GL_CreateContext, the result is that the window is shown, but the gl context doesn't seem to work (i.e. opengl function calls have no effect).

If the window is set to visible at least once (or shown, and subsequently hidden again), then, if the window is shown again after context generation, opengl calls work as intended.

This issue observed on Ubuntu Linux 10.04, 2.6.32-27-generic kernel, NVIDIA 195.36.24 driver. SDL head changeset was 5054:8af42aba8e17
Comment 1 Matthias 2011-01-20 14:03:51 UTC
Created attachment 554 [details]
simple program to illustrate bug behavior

There is a function showAndHide() in the main program. If you remove the comments, the program works as intended. If you do not remove the comments, the bug appears (i.e. broken SDL_GLContext).
Comment 2 driedfruit 2012-07-01 09:31:46 UTC
Created attachment 892 [details]
Possible fix

Please try the attached patch as a possible fix. I don't think it's related directly to hide/show, but to a general race condition.
Comment 3 Sam Lantinga 2013-05-21 01:27:20 UTC
Hey Ryan, can you look at this for SDL 2.0 release?  You can probably recruit Pierre-Loup if you want.
Comment 4 Ryan C. Gordon 2013-07-11 11:59:36 UTC
This is working here. I think we probably fixed it when we did all the tapdancing with fullscreen awhile ago, since it forced us to wait on some window mapping event or whatever, unrelated to this.

The specific reason this was failing, if I had to guess, was this section of the glXMakeCurrent docs:

"The first time ctx is made current to any thread, its viewport is set to the full size of drawable. Subsequent calls by any thread to glXMakeCurrent with ctx have no effect on its viewport."

Probably before the window was mapped, it had a 0x0 size.

If you're still having this problem with the latest SDL2 code, please see if adding "glViewport(0, 0, winw, winh);" right after the SDL_GL_CreateContext() fixes it...it's possible you had a 0x0 viewport.

(And if that fixes it, maybe we should force that in SDL_GL_CreateContext().)

Alternately: if you're still having this problem, see if SDL_GL_CreateContext() returned NULL. The reasons are still roughly the same, but that could also be why it failed, and we'd like to know where to fix this.

--ryan.
Comment 5 Sam Lantinga 2013-07-11 13:39:46 UTC
Ryan, I'm going to mark this waiting for feedback from Matthias so we get the info you're requesting.
Comment 6 Ryan C. Gordon 2013-07-12 18:52:57 UTC
(Sorry if you get a lot of copies of this email, we're touching dozens of bug reports right now.)

Tagging a bunch of bugs as target-2.0.0, Priority 1.

This means we're in the final stretch for an official SDL 2.0.0 release! These are the bugs we really want to fix before shipping if humanly possible.

That being said, we don't promise to fix them because of this tag, we just want to make sure we don't forget to deal with them before we bless a final 2.0.0 release, and generally be organized about what we're aiming to ship.

Hopefully you'll hear more about this bug soon. If you have more information (including "this got fixed at some point, nevermind"), we would love to have you come add more information to the bug report when you have a moment.

Thanks!
--ryan.
Comment 7 Ryan C. Gordon 2013-07-30 00:28:31 UTC
I'm resolving this bug, as it appears to be fixed. If you find it's still broken on the latest version of SDL, please feel free to reopen this bug.

--ryan.