Skip to content

Commit

Permalink
Merge pull request #238 from GuildMasterInfinite/gui-thread
Browse files Browse the repository at this point in the history
Use `IsGUIThread` to initialize message queue
  • Loading branch information
tomaka authored Jul 18, 2017
2 parents 2066909 + 8add21b commit 28eddb6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/platform/windows/events_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit 28eddb6

Please sign in to comment.