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 2083

Summary: Screen blink between the two last display
Product: SDL Reporter: Taiki <taiki>
Component: renderAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: taiki
Version: 2.0.0   
Hardware: x86_64   
OS: All   
Attachments: Testcase

Description Taiki 2013-09-02 21:40:02 UTC
I print the loading screen (SDL_RenderClear, SDL_RenderCopy) then clear the screen and display the splash screen. If I make the mouse leave the window, the window will display the loading screen.

In other context, 
If I call SDL_RenderPresent() (after using SDL_RenderFillRect, if relevant), the whole screen is shown as the color of the background except newly printed elements.

As it's probably a bit hard to get, here is a video: https://dl.dropboxusercontent.com/u/12087072/sdl.avi
(sorry for the framerate, there is no problem of fluidity)

On this laptop, DirectX isn't installed and install it seems to fix the issue. The point is that I can't ask my users to download something as big as DirectX just for my software.

Do you have any idea of how I could get rid of that behavior?

Thanks.
Comment 1 Taiki 2013-09-08 00:19:23 UTC
I made some researches, it seems that as DirectX isn't installed, D3D isn't available and the SDL fallback on OpenGL.

In WIN_GL_LoadLibrary, SDL try to load openGL32.dll using LoadLibrary("OPENGL32.DLL").
The problem seems to be than even if this file exist in System32 & SysWOW64, SDL fails at load it, can you look into that?
Comment 2 Taiki 2013-09-08 19:34:35 UTC
Okay, first change which fix things:
src/video/windows/SDL_windowsopengl.c:WIN_GL_LoadLibrary:88

The function receive an argument named path which is supposed to contain the path to opengl32.dll. In the case it's null, SDL will first try to load it from the environment variables then from an hard coded string.

Path is from type char also know on Windows as LPTCSTR.

path is then converted to wchar (LPTSTR) by WIN_UTF8ToString, sent to the variable named wpath which is then sent to LoadLibrary, in order to load OpenGL32.dll

The problem is that LoadLibrary expects to receive an argument from type LPTCSTR (http://msdn.microsoft.com/library/ms684175(VS.85).aspx). 

That make this call fail and the OpenGL loading to fail. I've no idea how it worked before (still investigating) but I guess it silently fallen back to DirectX which explain my failures when DirectX isn't installed.

I don't have anything to generate a patch but the fix is quite straightforward:

-LPTSTR wpath;
...
-wpath = WIN_UTF8ToString(path);
-_this->gl_config.dll_handle = LoadLibrary(wpath);
+_this->gl_config.dll_handle = LoadLibrary(path);
-SDL_free(wpath);
Comment 3 Taiki 2013-09-08 21:32:26 UTC
My previous patch fixed some weired issues when compiled but doesn't seems related to my core issue.

I'm wondering, WIN_GL_SwapWindow seems to be the core of SDL_RenderPresent and use SwapBuffers. Is it possible that there is two buffers of the display and SDL_RenderCopy only affect the hidden one? So if I add an element to the window, it won't get added to the current window but rather on a previous screen?
Comment 4 Sam Lantinga 2013-10-21 07:17:35 UTC
The latest snapshot should have better OpenGL library loading behavior.
Can you confirm?
http://www.libsdl.org/tmp/SDL-2.0.zip

With regard to multiple context behavior, can you attach a sample program (or a link to your source) so I can see what you're doing?

Thanks!
Comment 5 Taiki 2013-10-21 14:39:19 UTC
The library load properly but still behave strangely.

An example of the problem is attached

Freetype & SDL_TTF were recompiled manually without any change, I removed haptic & audio support from SDL via the header:

/* Enable various audio drivers
#define SDL_AUDIO_DRIVER_DSOUND 1
#define SDL_AUDIO_DRIVER_XAUDIO2    1
#define SDL_AUDIO_DRIVER_WINMM  1
#define SDL_AUDIO_DRIVER_DISK   1
#define SDL_AUDIO_DRIVER_DUMMY  1

/* Enable various input drivers
#define SDL_JOYSTICK_DINPUT 1
#define SDL_HAPTIC_DINPUT   1*/

#define SDL_AUDIO_DISABLED 1
#define SDL_JOYSTICK_DISABLED 1
#define SDL_HAPTIC_DISABLED 1
Comment 6 Taiki 2013-10-21 14:39:56 UTC
Created attachment 1388 [details]
Testcase
Comment 7 Taiki 2013-10-22 12:51:21 UTC
Also, to get the issue, you need to prevent SDL from loading DirectX, which it'll try to do even if it's asked not to do.
(remove DLL from System32 and SysWOW64 was enough)
Comment 8 Taiki 2013-11-10 11:33:16 UTC
The bug is also reproductible on OSX
Comment 9 Taiki 2013-11-24 22:24:18 UTC
Reproductible on OSX 10.8 & 10.9, I assume the underlying bug is present on every OpenGL implementation...
Comment 10 Sam Lantinga 2017-08-15 06:53:09 UTC
I believe this is fixed in the latest SDL snapshot:
http://www.libsdl.org/tmp/SDL-2.0.zip

Please reopen the bug if you're still having issues.

Thanks!