From f6581952bcfad0bf28c49180f86cf402f74ea723 Mon Sep 17 00:00:00 2001 From: geemion Date: Wed, 2 Jan 2019 23:44:31 +0800 Subject: [PATCH] win-capture/graphics-hook: Check if mutex abandoned It's possible that the mutexes used with shared memory capture to return WAIT_ABANDONED if OBS is shut down abnormally while the mutex is locked. --- plugins/win-capture/graphics-hook/graphics-hook.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/win-capture/graphics-hook/graphics-hook.c b/plugins/win-capture/graphics-hook/graphics-hook.c index 77864627..6e6a9aa8 100644 --- a/plugins/win-capture/graphics-hook/graphics-hook.c +++ b/plugins/win-capture/graphics-hook/graphics-hook.c @@ -467,10 +467,15 @@ uint64_t os_gettime_ns(void) static inline int try_lock_shmem_tex(int id) { int next = id == 0 ? 1 : 0; + DWORD wait_result = WAIT_FAILED; - if (WaitForSingleObject(tex_mutexes[id], 0) == WAIT_OBJECT_0) { + wait_result = WaitForSingleObject(tex_mutexes[id], 0); + if (wait_result == WAIT_OBJECT_0 || wait_result == WAIT_ABANDONED) { return id; - } else if (WaitForSingleObject(tex_mutexes[next], 0) == WAIT_OBJECT_0) { + } + + wait_result = WaitForSingleObject(tex_mutexes[next], 0); + if (wait_result == WAIT_OBJECT_0 || wait_result == WAIT_ABANDONED) { return next; } -- GitLab