From 145824f6ab46e38926beda87736fd240856078bf Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Thu, 21 Apr 2022 01:38:53 -0500
Subject: [PATCH] WGI: Only call RoUninitialize() if RoInitialize() succeeded
---
src/joystick/windows/SDL_windows_gaming_input.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/joystick/windows/SDL_windows_gaming_input.c b/src/joystick/windows/SDL_windows_gaming_input.c
index 39fadeab334..6c5ec552868 100644
--- a/src/joystick/windows/SDL_windows_gaming_input.c
+++ b/src/joystick/windows/SDL_windows_gaming_input.c
@@ -68,6 +68,7 @@ static struct {
EventRegistrationToken controller_added_token;
EventRegistrationToken controller_removed_token;
int controller_count;
+ SDL_bool ro_initialized;
WindowsGamingInputControllerState *controllers;
} wgi;
@@ -443,6 +444,7 @@ WGI_JoystickInit(void)
if (FAILED(WIN_RoInitialize())) {
return SDL_SetError("RoInitialize() failed");
}
+ wgi.ro_initialized = SDL_TRUE;
#ifndef __WINRT__
{
@@ -871,9 +873,12 @@ WGI_JoystickQuit(void)
__x_ABI_CWindows_CGaming_CInput_CIRawGameControllerStatics_remove_RawGameControllerRemoved(wgi.statics, wgi.controller_removed_token);
__x_ABI_CWindows_CGaming_CInput_CIRawGameControllerStatics_Release(wgi.statics);
}
- SDL_zero(wgi);
- WIN_RoUninitialize();
+ if (wgi.ro_initialized) {
+ WIN_RoUninitialize();
+ }
+
+ SDL_zero(wgi);
}
static SDL_bool