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@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Andrew Eikum 2019-06-11 10:29:14 -05:00 committed by Alexandre Julliard
parent 690838a0e0
commit f8a04c7f2e
1 changed files with 19 additions and 0 deletions

View File

@ -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);