Race condition: run_forever can dispatch events after the window is destroyed #415
Labels
B - bug
Dang, that shouldn't have happened
C - waiting on author
Waiting for a response or another PR
D - hard
Likely harder than most tasks here
DS - windows
P - normal
Great to have
Milestone
Background
While working on rust-windowing/glutin#998, my test program was crashing every time I closed the window:
This is ANGLE somewhere inside
eglSwapBuffers
, calling Windows’sGetClientRect
with the pointer returned byglutin::Window::platform_window
that Glutin had previously passed toeglCreateWindowSurface
, and asserting that this call succeeds. Here it was failing, with a debugger showing thatGetLastError()
returned 1400 which isERROR_INVALID_WINDOW_HANDLE
and showing indeed the that pointer as "unreadable memory".Conditions
Trying to reproduce this without ANGLE, I found out after a while that this problem only happens when:
events_loop.run_forever(…)
does some non-trivial work for each eventAs a result the closure keeps being called to handle events, even though the window is already gone and the
HWND
pointer is invalid.I don’t know if this problem is Windows-specific or if a similar race condition happens on other platforms.
Test case
Steps: run the program below on Windows, mouse over the window for a bit, then close it within a couple seconds.
Actual result:
GetClientRect failed. GetLastError: 1400
is printed dozens of times.Expected result: no output,
GetClientRect
always succeeds. Either the OS window is kept alive until all events are dispatched (or maybe as long as thewinit::Window
exists), or queued events are dropped when the window is destroyed.Alternatively,
winit::Window
gains a new method that tests whether the OS window still exists, and docs and examples point out that is should be used before doing anything with the window. (Maybeglutin::GlWindow::swap_buffers
also uses it to become a no-op on a closed window.)The text was updated successfully, but these errors were encountered: