Andrew Eikum : winebus.sys: Close SDL handles when a device is removed.

Alexandre Julliard julliard at winehq.org
Tue Jun 11 16:54:07 CDT 2019


Module: wine
Branch: master
Commit: f8a04c7f2e2c77eef663c5bb2109e3dbd51b22e0
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=f8a04c7f2e2c77eef663c5bb2109e3dbd51b22e0

Author: Andrew Eikum <aeikum at codeweavers.com>
Date:   Tue Jun 11 10:29:14 2019 -0500

winebus.sys: Close SDL handles when a device is removed.

This fixes opening SDL haptic handles after a device is removed and
re-added.

Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/winebus.sys/bus_sdl.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c
index 1a938aa..d24e21c 100644
--- a/dlls/winebus.sys/bus_sdl.c
+++ b/dlls/winebus.sys/bus_sdl.c
@@ -75,6 +75,7 @@ static void *sdl_handle = NULL;
 #define MAKE_FUNCPTR(f) static typeof(f) * p##f = NULL
 MAKE_FUNCPTR(SDL_GetError);
 MAKE_FUNCPTR(SDL_Init);
+MAKE_FUNCPTR(SDL_JoystickClose);
 MAKE_FUNCPTR(SDL_JoystickEventState);
 MAKE_FUNCPTR(SDL_JoystickGetGUID);
 MAKE_FUNCPTR(SDL_JoystickGetGUIDString);
@@ -89,6 +90,7 @@ MAKE_FUNCPTR(SDL_JoystickNumHats);
 MAKE_FUNCPTR(SDL_JoystickGetAxis);
 MAKE_FUNCPTR(SDL_JoystickGetHat);
 MAKE_FUNCPTR(SDL_IsGameController);
+MAKE_FUNCPTR(SDL_GameControllerClose);
 MAKE_FUNCPTR(SDL_GameControllerGetAxis);
 MAKE_FUNCPTR(SDL_GameControllerGetButton);
 MAKE_FUNCPTR(SDL_GameControllerName);
@@ -879,13 +881,28 @@ static BOOL set_mapped_report_from_event(SDL_Event *event)
 static void try_remove_device(SDL_JoystickID index)
 {
     DEVICE_OBJECT *device = NULL;
+    struct platform_private *private;
+    SDL_Joystick *sdl_joystick;
+    SDL_GameController *sdl_controller;
+    SDL_Haptic *sdl_haptic;
 
     device = bus_find_hid_device(&sdl_vtbl, ULongToPtr(index));
     if (!device) return;
 
+    private = impl_from_DEVICE_OBJECT(device);
+    sdl_joystick = private->sdl_joystick;
+    sdl_controller = private->sdl_controller;
+    sdl_haptic = private->sdl_haptic;
+
     IoInvalidateDeviceRelations(device, RemovalRelations);
 
     bus_remove_hid_device(device);
+
+    pSDL_JoystickClose(sdl_joystick);
+    if (sdl_controller)
+        pSDL_GameControllerClose(sdl_controller);
+    if (sdl_haptic)
+        pSDL_HapticClose(sdl_haptic);
 }
 
 static void try_add_device(SDL_JoystickID index)
@@ -1085,6 +1102,7 @@ NTSTATUS sdl_driver_init(void)
 #define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(sdl_handle, #f, NULL, 0)) == NULL){WARN("Can't find symbol %s\n", #f); goto sym_not_found;}
         LOAD_FUNCPTR(SDL_GetError);
         LOAD_FUNCPTR(SDL_Init);
+        LOAD_FUNCPTR(SDL_JoystickClose);
         LOAD_FUNCPTR(SDL_JoystickEventState);
         LOAD_FUNCPTR(SDL_JoystickGetGUID);
         LOAD_FUNCPTR(SDL_JoystickGetGUIDString);
@@ -1099,6 +1117,7 @@ NTSTATUS sdl_driver_init(void)
         LOAD_FUNCPTR(SDL_JoystickGetAxis);
         LOAD_FUNCPTR(SDL_JoystickGetHat);
         LOAD_FUNCPTR(SDL_IsGameController);
+        LOAD_FUNCPTR(SDL_GameControllerClose);
         LOAD_FUNCPTR(SDL_GameControllerGetAxis);
         LOAD_FUNCPTR(SDL_GameControllerGetButton);
         LOAD_FUNCPTR(SDL_GameControllerName);




More information about the wine-cvs mailing list