mirror of
				https://github.com/libsdl-org/SDL.git
				synced 2025-10-26 12:27:44 +00:00 
			
		
		
		
	haptics: Enumerate XInput/DInput joysticks after haptic init
Since the haptic subsystem is usually initialized after the joystick subsystem, the initial calls to HapticMaybeAddDevice() from inside SDL_JoystickInit() will arrive too early to be handled by the haptic subsystem. We need to add those haptic devices for those already present joysticks ourselves.
This commit is contained in:
		| @@ -52,12 +52,28 @@ static int numhaptics = 0; | |||||||
| int | int | ||||||
| SDL_SYS_HapticInit(void) | SDL_SYS_HapticInit(void) | ||||||
| { | { | ||||||
|  |     JoyStick_DeviceData* device; | ||||||
|  |  | ||||||
|     if (SDL_DINPUT_HapticInit() < 0) { |     if (SDL_DINPUT_HapticInit() < 0) { | ||||||
|         return -1; |         return -1; | ||||||
|     } |     } | ||||||
|     if (SDL_XINPUT_HapticInit() < 0) { |     if (SDL_XINPUT_HapticInit() < 0) { | ||||||
|         return -1; |         return -1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /* The joystick subsystem will usually be initialized before haptics, | ||||||
|  |      * so the initial HapticMaybeAddDevice() calls from the joystick | ||||||
|  |      * subsystem will arrive too early to create haptic devices. We will | ||||||
|  |      * invoke those callbacks again here to pick up any joysticks that | ||||||
|  |      * were added prior to haptics initialization. */ | ||||||
|  |     for (device = SYS_Joystick; device; device = device->pNext) { | ||||||
|  |         if (device->bXInputDevice) { | ||||||
|  |             SDL_XINPUT_HapticMaybeAddDevice(device->XInputUserId); | ||||||
|  |         } else { | ||||||
|  |             SDL_DINPUT_HapticMaybeAddDevice(&device->dxdevice); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return numhaptics; |     return numhaptics; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Cameron Gutman
					Cameron Gutman