From 1a9641e3d99b4920d4a894218b05fd76bb774aed Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 6 Aug 2011 20:04:48 -0700 Subject: [PATCH] Add a hack to help make sure WM_QUIT gets received by the primary buffer's thread If the primary buffer is cleared immediately after it's pre-inited, so WM_QUIT gets sent before the threead has a chance to call GetMessageA, it never receives the message and thus never quits. --- primary.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/primary.c b/primary.c index cd996a4..340f760 100644 --- a/primary.c +++ b/primary.c @@ -405,7 +405,17 @@ void DS8Primary_Clear(DS8Primary *This) { PostThreadMessageA(This->thread_id, WM_QUIT, 0, 0); if(WaitForSingleObject(This->thread_hdl, 1000) != WAIT_OBJECT_0) - ERR("Thread wait timed out\n"); + { + /* HACK: Apparently, if the device is initialized (thus the primary + * buffer has PreInit called) then immediately deleted (the primary + * buffer has Clear called), the WM_QUIT message gets sent before + * the thread has a chance to run which apparently prevents it from + * receiving the message. + * If the wait attempt fails, try sending the message again. */ + PostThreadMessageA(This->thread_id, WM_QUIT, 0, 0); + if(WaitForSingleObject(This->thread_hdl, 1000) != WAIT_OBJECT_0) + ERR("Thread wait timed out\n"); + } CloseHandle(This->thread_hdl); } -- 2.11.4.GIT