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 3030

Summary: SDL_RecreateWindow fails to restore title, icon, etc. (at least on Windows)
Product: SDL Reporter: Adam M. <adam>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.3   
Hardware: x86_64   
OS: Windows 7   
Attachments: proposed patch (v1)

Description Adam M. 2015-06-21 00:41:38 UTC
On Windows, SDL_RecreateWindow fails to restore the title, icon, etc. because at the point when it tries to set them the HWND is -1.
Comment 1 Adam M. 2015-06-21 00:43:31 UTC
Sorry, I was reading the wrong thing in the debugger output. The HWND is not -1. Nonetheless, it fails to restore the title.
Comment 2 Adam M. 2015-06-21 00:53:35 UTC
Created attachment 2199 [details]
proposed patch (v1)

It loses the title and icon when window recreation fails. For instance, this may happen when trying to create an OpenGL ES window on a system that doesn't support it. But at that point, the title and icon have already been lost.

I've attached a patch that delays clearing out the title and icon until later.
Comment 3 Adam M. 2015-06-21 02:53:41 UTC
This also fixes a small memory leak, I think.
Comment 4 Sam Lantinga 2015-06-22 00:17:47 UTC
Why does setting the title and icon after the window is created fail?
Comment 5 Adam M. 2015-06-22 05:26:28 UTC
It doesn't fail if the window was created. The problem is if the window is not created, in which case it returns -1, but at that point it already NULLed out the window->title and window->icon pointers. Then on the next call, even if it succeeds in creating the window, it can't set the title or icon because they've been lost (and leaked).

I moved the code to NULL the pointers until after the window creation attempt, so that if it returns with an error it still has the title and icon for next time.
Comment 6 Adam M. 2015-06-22 13:50:38 UTC
If you want to reproduce this problem for yourself, you can do the following:

1. Start up a Windows system that doesn't support hardware acceleration (e.g. a VirtualBox instance without hardware acceleration enabled or the DirectX guest tools installed).
2. Create a normal window.
3. Set the title.
4. Create a renderer with SDL_RendererFlags of 0.

The video code will attempt to initialize various renderers in order to find one that works. Some of them will fail and call SDL_RecreateWindow. At least one of the times, SDL_RecreateWindow will fail to recreate the window (returning -1 after the code "if (_this->CreateWindow(_this, window) < 0) {"), after which subsequent calls to SDL_RecreateWindow will be unable to restore the title.

You'll wind up with a window that has no title.
Comment 7 Sam Lantinga 2015-06-23 06:38:51 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/952ff8a5076f