mpv-player/mpv — pull request #1136 by rossy2401 (2014-09-30 11:55:59+00:00)
Title: Fix hang with libmpv and --wid embedding

I've been experimenting with libmpv in a Qt app on Windows. In my app, the parent HWND is destroyed before the libmpv instance is terminated. When this happens, libmpv locks up and mpv_terminate_destroy never returns. This seems to be because destroying mpv's window stops WM_USER wakeups.

This change fixes it by making sure the event loop exits when the window is destroyed. Any remaining requests to the GUI thread can be handled directly by mp_dispatch_queue_process.

This also removes the PeekMessage trick. Though it's harmless, I think it's unnecessary when messages are delivered to a window. CreateWindowEx sends the WM_NCCREATE and WM_CREATE messages to the window and they are processed synchronously before the function returns, so a message queue definitely exists on the thread by that point. WM_USER wakeups should work from then until PostQuitMessage is called and the message loop is exited.