From f1cb1a42ccf415e708db2e94d81b1a371bf073e2 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Tue, 10 Mar 2020 07:11:18 -0700 Subject: [PATCH] win-capture: Try window handle 0 if actual handle fails Certain UWP programs can't obtain a normal window handle from their API for whatever reason (this was observed with minecraft win10 edition), so if the normal window handle on the map fails, try window handle 0 instead. --- plugins/win-capture/game-capture.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/plugins/win-capture/game-capture.c b/plugins/win-capture/game-capture.c index c4ccbad3..57d33cfc 100644 --- a/plugins/win-capture/game-capture.c +++ b/plugins/win-capture/game-capture.c @@ -1239,6 +1239,17 @@ static inline bool init_events(struct game_capture *gc) enum capture_result { CAPTURE_FAIL, CAPTURE_RETRY, CAPTURE_SUCCESS }; +static inline bool init_data_map(struct game_capture *gc, HWND window) +{ + wchar_t name[64]; + swprintf(name, 64, SHMEM_TEXTURE "_%" PRIu64 "_", + (uint64_t)(uintptr_t)window); + + gc->hook_data_map = + open_map_plus_id(gc, name, gc->global_hook_info->map_id); + return !!gc->hook_data_map; +} + static inline enum capture_result init_capture_data(struct game_capture *gc) { gc->cx = gc->global_hook_info->cx; @@ -1252,15 +1263,17 @@ static inline enum capture_result init_capture_data(struct game_capture *gc) CloseHandle(gc->hook_data_map); - wchar_t name[64]; - swprintf(name, 64, SHMEM_TEXTURE "_%" PRIu64 "_", - (uint64_t)(uintptr_t)gc->window); + DWORD error = 0; + if (!init_data_map(gc, gc->window)) { + error = GetLastError(); - gc->hook_data_map = - open_map_plus_id(gc, name, gc->global_hook_info->map_id); + /* if there's an error, try with 0 (for UWP programs) */ + if (init_data_map(gc, NULL)) { + error = 0; + } + } if (!gc->hook_data_map) { - DWORD error = GetLastError(); if (error == 2) { return CAPTURE_RETRY; } else { -- GitLab