| Summary: | SDL_RecreateWindow fails to restore title, icon, etc. (at least on Windows) | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Adam M. <adam> |
| Component: | video | Assignee: | 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
Sorry, I was reading the wrong thing in the debugger output. The HWND is not -1. Nonetheless, it fails to restore the title. 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.
This also fixes a small memory leak, I think. Why does setting the title and icon after the window is created fail? 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. 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.
Fixed, thanks! https://hg.libsdl.org/SDL/rev/952ff8a5076f |