Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on Windows when opening second HapticFromJoystick #1127

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

Crash on Windows when opening second HapticFromJoystick #1127

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: HG 2.0
Reported for operating system, platform: Windows 7, x86

Comments on the original bug report:

On 2013-10-18 21:08:05 +0000, Nicholas Hastings wrote:

As discussed on the mailing list, there is a crash in the haptics subsystem, on Windows, when SDL_HapticOpenFromJoystick is called for a second device.

The underlying cause may be the same as in bug 2126, but I wanted to file separately in the case that it's not since the trigger is different.

To reproduce, have more than one joystick or game controller supporting haptics connected, such as two Xbox 360 controllers. Then open each as a joystick, and then open a haptic from each with SDL_HapticOpenFromJoystick.

The crash is in SDL_SYS_JoystickSameHaptic on this line,
http://hg.libsdl.org/SDL/file/b7c1c84c33e3/src/haptic/windows/SDL_syshaptic.c#l649

Simplified repro code, assuming at least two haptic joysticks are attached:

SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC);

int numJoysticks = SDL_NumJoysticks();

for (int i = 0; i < numJoysticks; ++i)
{
SDL_Joystick *pJoy;
pJoy = SDL_JoystickOpen(i);
if (!pJoy || !SDL_JoystickIsHaptic(pJoy))
continue;

// This will crash on the second invocation
SDL_Haptic *pHaptic = SDL_HapticOpenFromJoystick(pJoy);

}

On 2013-10-21 03:15:48 +0000, Ryan C. Gordon wrote:

This should be fixed by http://hg.libsdl.org/SDL/rev/70f1d63482d0 ...

This line...

if ((joystick->hwdata->bXInputHaptic == haptic->hwdata->bXInputHaptic) && (haptic->hwdata->userid == joystick->hwdata->userid)) {

...would fail if both devices were different XInput controllers, and then try to use them as bogus pointers through the DirectInput API. If was a goofy piece of logic.

--ryan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant