Skip to content

Commit

Permalink
Handle WM_GETOBJECT while the window is being destroyed (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcampbell authored Nov 18, 2021
1 parent 0e933a7 commit 3c84b94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion platforms/windows/examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,14 @@ extern "system" fn wndproc(window: HWND, message: u32, wparam: WPARAM, lparam: L
LRESULT(0)
}
WM_GETOBJECT => {
let window_state = unsafe { &*get_window_state(window) };
let window_state = unsafe { get_window_state(window) };
if window_state.is_null() {
// We need to be prepared to gracefully handle WM_GETOBJECT
// while the window is being destroyed; this can happen if
// the thread is using a COM STA.
return unsafe { DefWindowProcW(window, message, wparam, lparam) };
}
let window_state = unsafe { &*window_state };
window_state.manager.handle_wm_getobject(wparam, lparam)
}
WM_SETFOCUS | WM_EXITMENULOOP | WM_EXITSIZEMOVE => {
Expand Down
9 changes: 8 additions & 1 deletion platforms/windows/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ extern "system" fn wndproc(window: HWND, message: u32, wparam: WPARAM, lparam: L
LRESULT(0)
}
WM_GETOBJECT => {
let window_state = unsafe { &*get_window_state(window) };
let window_state = unsafe { get_window_state(window) };
if window_state.is_null() {
// We need to be prepared to gracefully handle WM_GETOBJECT
// while the window is being destroyed; this can happen if
// the thread is using a COM STA.
return unsafe { DefWindowProcW(window, message, wparam, lparam) };
}
let window_state = unsafe { &*window_state };
window_state.manager.handle_wm_getobject(wparam, lparam)
}
WM_SETFOCUS | WM_EXITMENULOOP | WM_EXITSIZEMOVE => {
Expand Down

0 comments on commit 3c84b94

Please sign in to comment.