Closed SDLBugzilla closed 1 year ago
DOSBox-X developer here: The in-tree SDL1 library was modified for Win32 builds to separate the SDL window into a parent and child window, and a separate thread to manage one of them, so that moving/resizing the window or using the menus does not halt emulation. This trick is how DOSBox-X is able to continue running normally even when resizing. Feel free to adapt if desired.
https://github.com/joncampbell123/dosbox-x/tree/master/vs/sdl
Not every SDL application needs this of course, so if it is added let it be an option on, say, SDL_Init()
It seems very odd that this kind of industry leading library is unable to let my code run when the window is dragged. For like a decade, from what I'm reading here? Just don't render anything, let all SDL code fail horribly, anything, but for FSM sake, don't block my code!
SDL doesn't know ahead of time that you're entering the message pump to be dragged for an indeterminate amount of time. This is a limitation of the design of the SDL_Event loop interacting with the Windows event loop. There are many workarounds, but they'd need to be implemented and all require changes on the part of the app.
Perhaps the design could be revisited in SDL3 to not interact poorly, but I'm not sure what it would look like.
I am sure the techicalities of why this is a problem are sound, and I am sure it's the usual microsoft thing that's causing it. However, the consequences are absolutely terrible. All I'm saying, all my criticism is regarding priorities. I'm sure music visualizations and things like that are loving it. If they are smart, they'll probably let the music go bwbwbwbwbw until you let the window go. Heck, I'm going mad just having my avg time measures f'ed up for seconds when I have to move the window out of the way of the console after starting all the time.
Btw. all of that needs to be combined with all I've read how you must not move the rendering or the event loop to different threads. All of this appears pretty extreme to me. Which is of course measured by the standing SDL seems to have. It's not like I would complain about some dude's engine that way. Anyway, cheerio everyone. Just felt that this whole thing needed quite the kick in the behind.
There is a reason dragging/resizing the window or using the menus blocks execution of your SDL application.
The way Windows handles those interactions, and always has handled it going back to Windows 1.x even, is that DefWindowProc() goes into it's own event handling loop to handle that action. This of course blocks the SDL event handling loop.
The way DOSBox-X handles it is by modding the SDL library to maintain both a parent top level window and a child window inside, and then a separate thread handles message handling. If DefWindowProc() blocks for window size/move and menu interaction, then that thread is blocked while the main SDL application continues to run unimpeded.
Perhaps official SDL development can handle it differently or possibly cleaner, but that's how you can avoid the blocking issue entirely.
Appreciate the help, but really I'm not using a cross platform thingy that "is mainly used to handle cross platform window management" to work around window management tailored to specific platforms. The only solution that works is that SDL is just able to move a running program across the screen, even on an outlandish platform like windows.
We're still discussing what the appropriate way to work around this Windows limitation should be for SDL3, which is why this issue is still open.
While we discuss that, I'm going to lock this thread, as I think we have enough feedback telling us that people feel strongly about finding a resolution.
I've added a solution that dovetails nicely with the new main callbacks in SDL 3.0 and if you're not using that you can set an event watcher to handle expose events and draw then.
Thanks for all the feedback!
Being angry because you are completely ignorant on a topic doesn't help you or anyone else. This issue is indeed related to Win32 modal loops, and also applies if you use Win32 directly. A little search on the internet, or just reading this conversation, would have told you about that. Moreover, this problem is solved now, so I don't see the point of your intervention.
Anyway, props to the SDL team for your amazing work on this library, you don't deserve such rude comments.
@RT2Code It should be the SDL team that apologizes for the rude comments themselves. If you make a multiplatform library like this, it is your responsibility to make sure that your event loop interacts correctly with ALL of the platforms. SDL had this issue for several years and they kept brushing it off, as many of the other people in this conversation have pointed out. @icculus 's comments above, berating people because they expect this library to not block on window resizes (or even holding down one of the window buttons on macOS), and even trying to compare this to someone unplugging an ethernet cable, was extremely disappointing and completely uncalled for.
And no, the problem isn't solved. It still exists in SDL2. We still have to use a workaround for SDL2. Your "example" StackOverflow link (as if StackOverflow is the best place to get programming advice, lmao) isn't using the Windows API correctly. I think you will find that the Win32 API documents what is expected and what isn't, unlike SDL. This is well explained in one of the StackOverflow answers:
When DefWindowProc handles WM_SYSCOMMAND with either SC_MOVE or SC_SIZE in the wParam, it enters a loop until the user stops it by releasing the mouse button, or pressing either enter or escape. It does this because it allows the program to render both the client area (where your widgets or game or whatever is drawn) and the borders and caption area by handling WM_PAINT and WM_NCPAINT messages (you should still receive these events in your Window Procedure).
It works fine for normal Windows apps, which do most of their processing inside of their Window Procedure as a result of receiving messages. It only effects programs which do processing outside of the Window Procedure, such as games (which are usually fullscreen and not affected anyway).
Many people have solved this problem easily. It only took the SDL team many years to fix it.
icculus 's comments above, berating people because they expect this library to not block
I didn't berate people, I offered several possible technical workarounds, and I locked this thread because it keeps generating unhelpful commentary like this, which is also why I'm locking it again now.
This is fixed for the SDL 2.30 release, in 509c70c6982b6927f5a8d4fb32f9319cbaf0c2ef
This bug report was migrated from our old Bugzilla tracker.
These attachments are available in the static archive:
patch (SDL_modeless_size_move.patch, text/plain, 2014-02-06 05:21:48 +0000, 11407 bytes)Reported in version: HG 2.1 Reported for operating system, platform: Windows (All), All
Comments on the original bug report:
On 2013-08-30 01:00:19 +0000, wrote:
On 2014-01-20 05:04:25 +0000, Nathaniel Fries wrote:
On 2014-01-20 16:48:16 +0000, Nathaniel Fries wrote:
On 2014-01-20 16:54:40 +0000, Nathaniel Fries wrote:
On 2014-02-06 05:21:48 +0000, Nathaniel Fries wrote:
On 2014-02-09 10:08:44 +0000, Sam Lantinga wrote:
On 2014-02-09 12:43:34 +0000, Nathaniel Fries wrote:
On 2014-02-09 20:36:01 +0000, Sam Lantinga wrote:
On 2014-02-09 23:31:57 +0000, Nathaniel Fries wrote:
On 2014-02-20 21:05:23 +0000, Nathaniel Fries wrote:
On 2014-02-25 12:53:59 +0000, Sam Lantinga wrote:
On 2014-03-05 11:12:47 +0000, Andreas Ertelt wrote:
On 2014-03-06 10:06:56 +0000, Andreas Ertelt wrote:
On 2014-03-09 01:08:36 +0000, Nathaniel Fries wrote:
On 2014-03-11 07:11:10 +0000, Andreas Ertelt wrote:
On 2014-03-12 19:09:40 +0000, Nathaniel Fries wrote:
On 2014-03-12 20:40:33 +0000, Nathaniel Fries wrote:
On 2014-03-16 09:42:03 +0000, Nathaniel Fries wrote:
On 2019-12-07 17:00:27 +0000, Jake Del Mastro wrote:
On 2020-03-24 21:13:36 +0000, Ryan C. Gordon wrote:
On 2020-04-16 16:50:42 +0000, Ron Aaron wrote:
On 2020-04-16 19:19:48 +0000, Andreas Ertelt wrote:
On 2020-04-18 13:08:58 +0000, Andreas Ertelt wrote:
On 2020-07-12 09:53:51 +0000, Jack C wrote: