Commits

Alex Szpakowski  committed 786cac1

Fixed compilation in Windows, and worked around an integer overflow bug in SDL's Xinput code

  • Participants
  • Parent commits b1506b1
  • Branches joystick-vibrate

Comments (0)

Files changed (1)

File src/modules/joystick/sdl/Joystick.cpp

 
 bool Joystick::setVibration(float left, float right)
 {
-	// TODO: support non-infinite durations? The updated Tattiebogle Xbox
+	// TODO: support non-infinite durations? The working Tattiebogle Xbox
 	// controller driver in OS X seems to ignore durations under 1 second.
 
 	left = std::min(std::max(left, 0.0f), 1.0f);
 
 	if ((features & SDL_HAPTIC_LEFTRIGHT) != 0)
 	{
-		vibration.effect = {};
+		memset(&vibration.effect, 0, sizeof(SDL_HapticEffect));
 		vibration.effect.type = SDL_HAPTIC_LEFTRIGHT;
 
-		vibration.effect.leftright.length = SDL_HAPTIC_INFINITY;
+		// SDL's Xinput code has an int. overflow bug with SDL_HAPTIC_INFINITY.
+		const Uint32 long_time = 1000 * 60 * 60 * 2;
+
+		vibration.effect.leftright.length = long_time;
 		vibration.effect.leftright.large_magnitude = Uint16(left * LOVE_UINT16_MAX);
 		vibration.effect.leftright.small_magnitude = Uint16(right * LOVE_UINT16_MAX);
 
 		vibration.data[0] = vibration.data[2] = Uint16(left * 0x7FFF);
 		vibration.data[1] = vibration.data[3] = Uint16(right * 0x7FFF);
 
-		vibration.effect = {};
+		memset(&vibration.effect, 0, sizeof(SDL_HapticEffect));
 		vibration.effect.type = SDL_HAPTIC_CUSTOM;
 
 		vibration.effect.custom.length = SDL_HAPTIC_INFINITY;