| Summary: | SDL_SetWindowSize after leaving fullscreen doesn't work | ||
|---|---|---|---|
| Product: | SDL | Reporter: | JoeRosselli+libsdl |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | ASSIGNED --- | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | amaranth72, philipp.wiesemann |
| Version: | 2.0.2 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
Is this on Mir, Wayland or X11? Hi Philipp, it's running on X11 I don't think SDL_PollEvent and the SDL windowing functions can be used on threads other than the main thread (if it works, it may just be a coincidence or non-portable). Well everything SDL related is running on one thread. As far as I can tell from the documentation if it's all running on the same thread it should be fine, even if that isn't the main thread. For instance, I couldn't SDL_Init on the main thread and then try to create windows on a separate thread. I think it will still reproduce if everything was moved to the main thread, I'll try that after work. Keeping everything in one non-main thread might work reliably on Linux, I'm not sure. However I'm pretty sure it won't work in OS X (hence my non-portable comment), and it definitely won't work on iOS. There are probably other operating systems where it won't work at all. I've gone ahead and verified that if you get rid of the separate thread and run the same code right from within main (on the main thread) the bug still reproduces, so that wasn't causing the problem. It's unrelated now but I just wanted to note that in the original scenario I'm not sure how SDL would even have a way of knowing it wasn't on the main thread. As long as I wasn't making any cross-thread calls I still feel like that's a completely valid use case. But moving on .. Ok, so more info: I went ahead and tested this on Windows as well (Win 7, x64). Discovered some interesting behavior. - On both, the SDL_WINDOWPOS_CENTERED flag is respected and the 800x600 window launches in the center of the screen. - On Ubuntu, the step to increase the window size to 1920x1080 (unmaximized) causes the window to fill my entire monitor (monitor is running at 1920x1080), it seems to "lock" onto the whole screen, in that the title integrates into Ubuntu's top toolbar. On Windows, however, the same call keeps the window's top-left corner in the same position, and pushes the bottom right corner out until the window is 1920x1080 in size. - After running through the steps on Windows, the last step was able to resize the window to 800x600, and seemed to work where on Ubuntu it did not. However, I was suspicious about how the initial increase to 1920x1080 differed on both. I've discovered that on Ubuntu, after the initial increase to 1920x1080, if I manually move the window around at all, which "unlocks" the window, as in it's a 1920x1080 window with its titlebar not integrated into Ubuntu's top toolbar, then after going through the steps, SDL is able to resize it back down to 800x600 successfully at the end. Sorry if that's hard/complicated to follow ... it seems like the problem only reproduces on Ubuntu now. May be a problem in Ubuntu/X11 for all I know, I'm not sure. (In reply to JoeRosselli+libsdl from comment #6) > It's unrelated now but I just wanted to note that in the original scenario > I'm not sure how SDL would even have a way of knowing it wasn't on the main > thread. As long as I wasn't making any cross-thread calls I still feel like > that's a completely valid use case. Trust me, it won't work on some backends at least. For example on iOS it will not work - I haven't tested other backends and I don't really intend to, but I do have intimate knowledge about SDL's iOS backend since I wrote much of is current code. |
OS: Ubuntu x64 SDL: 2.0.2 (latest in apt) After leaving fullscreen mode, trying to set the window size seems to have no effect. The steps I'm using are: 1) Create a new window at 800x600 window size 2) Set window size to 1920x1080 using SDL_SetWindowSize 3) Switch to fullscreen mode using SDL_SetWindowFullscreen and SDL_WINDOW_FULLSCREEN flag 4) Leave fullscreen mode using SDL_SetWindowFullscreen and 0 flag 5) Try to resize the window back to 800x600 using SDL_SetWindowSize At step 5, the window remains at 1920x1080 resolution, the call to change it back down doesn't work. See below for sample code that reproduces the problem. Every time you press "F1", it should move one step between steps 2 and 5 that I detailed above. "Escape" key to quit. If you want to build the code, it will require c++11. The window also looks broke as I'm not drawing anything to it in this example, that's expected. Thanks for taking the time to take a look at this. [code] #include <thread> #include <SDL2/SDL.h> void SDLThread() { SDL_Init(SDL_INIT_VIDEO); SDL_Window *mainWindow = SDL_CreateWindow("Test Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); int action = 0; bool runThread = true; while (runThread) { SDL_Event sdlEvent; while (SDL_PollEvent(&sdlEvent) != 0) { if (sdlEvent.type == SDL_KEYDOWN) { if (sdlEvent.key.keysym.sym == SDLK_ESCAPE) { runThread = false; } if (sdlEvent.key.keysym.sym == SDLK_F1) { if (action == 0) { SDL_SetWindowSize(mainWindow, 1920, 1080); } else if (action == 1) { SDL_SetWindowFullscreen(mainWindow, SDL_WINDOW_FULLSCREEN); } else if (action == 2) { SDL_SetWindowFullscreen(mainWindow, 0); } else if (action == 3) { SDL_SetWindowSize(mainWindow, 800, 600); } action++; } } } std::this_thread::sleep_for(std::chrono::milliseconds(10)); } SDL_DestroyWindow(mainWindow); } int main() { std::thread sdlThread(SDLThread); sdlThread.join(); return 0; } [/code]