From 8add21b04f0978ac25733a227d682c87311f5e16 Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Tue, 18 Jul 2017 20:57:22 +0300 Subject: [PATCH] Use `IsGUIThread` to initialize message queue --- src/platform/windows/events_loop.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/platform/windows/events_loop.rs b/src/platform/windows/events_loop.rs index d3acde0d..6f34c0a0 100644 --- a/src/platform/windows/events_loop.rs +++ b/src/platform/windows/events_loop.rs @@ -98,16 +98,16 @@ impl EventsLoop { }); unsafe { - let mut msg = mem::uninitialized(); - // Calling `PostThreadMessageA` on a thread that does not have an events queue yet - // will fail. In order to avoid this situation, we call `PeekMessage` to initialize + // will fail. In order to avoid this situation, we call `IsGuiThread` to initialize // it. - user32::PeekMessageA(&mut msg, ptr::null_mut(), 0, 0, 0); + user32::IsGUIThread(1); // Then only we unblock the `new()` function. We are sure that we don't call // `PostThreadMessageA()` before `new()` returns. local_block_tx.send(()).unwrap(); + let mut msg = mem::uninitialized(); + loop { if user32::GetMessageW(&mut msg, ptr::null_mut(), 0, 0) == 0 { // Only happens if the message is `WM_QUIT`.