Problem with event processing on win32 -- hang when moving app window

hi,

we have a problem when moving the app window, the application loop hangs
until one stops to drag the window. this problem only occurs on win32. i
have already digged into the sdl sources and found out that on win32 the
input processing cannot be done in an own thread, but only in main thread.
this may be the problem!?

we pick up the inputs in main loop using SDL_PollEvent. as our application
loop must not be interrupted because of internal timers, networking etc. it
is important that we find a work-around for this problem.

any idea how to solve this problem other than putting the rest of the
application main loop into another thread and synching the sdl events in
main thread with that loop thread? this solution would cause a lot of
restructuring of our code :frowning:

thanks in advance for every help :wink:

cheers
boto

we have a problem when moving the app window, the application loop hangs
until one stops to drag the window. this problem only occurs on win32.
[snip]
we pick up the inputs in main loop using SDL_PollEvent. as our application
loop must not be interrupted because of internal timers, networking etc. it
is important that we find a work-around for this problem.

How about getting the window handle with SDL_GetWMInfo(), installing a
new WNDPROC with SetWindowLong() that listens for WM_MOVING messages,
and update your network/etc code there?

Something a la:

SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if(SDL_GetWMInfo(&info)) {
WNDPROC sdl_wndproc =
(WNDPROC)SetWindowLong(info.window,GWL_WNDPROC,(LONG)your_wndproc);
}

And your WNDPROC:

LRESULT CALLBACK your_wndproc(HWND hWnd,UINT nMsg,WPARAM wParam,LPARAM lParam) {
if(nMsg == WM_MOVING) {
do_your_stuff();
}
return sdl_wndproc(hWnd,nMsg,wParam,lParam);
}

I don’t know whether it would work, though.On 4/26/06, Botorabi wrote:


Cheers,
Rasmus Neckelmann
http://royal.flof.dk/rasmus

Hi
Is there any “out of the box” solution for this problem?

I needed to do something similar, I outlined my solution in this thread:

Orthogonal to using a callback from timer events like oviano does, you can use a callback (via AddEventWatch or SetEventFilter) from SDL_WINDOWEVENT_MOVED and SDL_WINDOWEVENT_SIZE_CHANGED. This will prevent hang-ups as long as the user is actively moving/sizing the window (i.e. moving their mouse around). It will not prevent hang-ups if they’re within the moving/sizing modal loop but not actively moving/sizing (i.e. holding down the mouse button but not moving it).

I don’t know what your criteria for “out-of-the-box” is, but a solution like this is still pretty idiomatic to pure SDL, I think.

“Out of the box” - when without any additional callbacks, hints and so on, the main thread is not blocked with moving a window or with holding a title.

I thought I may as well upload my modified source, in case it is useful to someone doing something similar.

There are a bunch of other mods for various platforms, but for the specific things being discussed here you could search in this source code for UpdateCallback and see how I implemented this.