From 209bcda1f4e544ae81b6b24cd3cd6d51644b9d9d Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 15 Dec 2016 20:02:52 -0800 Subject: [PATCH] win-capture: Wait a few frames for hook to load Now that the game capture hook creates and controls all the synchronization objects, it's no longer possible to expect that the hook is fully loaded by the time game capture tries to initialize it. In that case, allow game capture to retry the hook for a few frames before assuming something failed. --- plugins/win-capture/game-capture.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/win-capture/game-capture.c b/plugins/win-capture/game-capture.c index 7fed5fe39..e02690cc6 100644 --- a/plugins/win-capture/game-capture.c +++ b/plugins/win-capture/game-capture.c @@ -148,6 +148,7 @@ struct game_capture { HANDLE target_process; HANDLE texture_mutexes[2]; wchar_t *app_sid; + int retrying; union { struct { @@ -316,6 +317,9 @@ static void stop_capture(struct game_capture *gc) gc->wait_for_target_startup = false; gc->active = false; gc->capturing = false; + + if (gc->retrying) + gc->retrying--; } static inline void free_config(struct game_capture_config *config) @@ -718,7 +722,16 @@ static inline bool init_texture_mutexes(struct game_capture *gc) gc->texture_mutexes[1] = open_mutex_gc(gc, MUTEX_TEXTURE2); if (!gc->texture_mutexes[0] || !gc->texture_mutexes[1]) { - warn("failed to open texture mutexes: %lu", GetLastError()); + DWORD error = GetLastError(); + if (error == 2) { + if (!gc->retrying) { + gc->retrying = 2; + info("hook not loaded yet, retrying.."); + } + } else { + warn("failed to open texture mutexes: %lu", + GetLastError()); + } return false; } @@ -1047,6 +1060,7 @@ static bool init_hook(struct game_capture *gc) gc->window = gc->next_window; gc->next_window = NULL; gc->active = true; + gc->retrying = 0; return true; }