We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1487 - SDL_HapticOpenFromJoystick() crashes!! SDL_NumHaptics() returning wrong value.
Summary: SDL_HapticOpenFromJoystick() crashes!! SDL_NumHaptics() returning wrong value.
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: haptic (show other bugs)
Version: HG 2.0
Hardware: x86 Mac OS X 10.7
: P2 critical
Assignee: Edgar Simo
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.0
Depends on:
Blocks:
 
Reported: 2012-04-30 14:45 UTC by Rodrigo Cardoso
Modified: 2013-07-31 00:43 UTC (History)
2 users (show)

See Also:


Attachments
More defensive checks to make sure stuff works. (16.13 KB, patch)
2012-05-06 02:33 UTC, Edgar Simo
Details | Diff
Updated version of the more defensive checks patch. (2.76 KB, patch)
2013-07-14 19:45 UTC, Edgar Simo
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rodrigo Cardoso 2012-04-30 14:45:43 UTC
I am trying to use SDL_haptic for the first time and already found a bug =P
I used a Xbox 360 Wireless controller in Mac OS X 10.7 with TattieBogle's driver (http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver)

The haptic feedback is working in other apps.
And cleary there is something wrong because SDL_JoystickIsHaptic() returns true, but SDL_NumHaptics() return 0;



========================
Test code:

printf("%i joysticks were found.\n%i are hapitcs.\n", SDL_NumJoysticks(), SDL_NumHaptics() );
	for (int i = 0; i < SDL_NumJoysticks(); i++) {
		SDL_Joystick *joy = SDL_JoystickOpen(i);
		printf("is haptic?: %d;", SDL_JoystickIsHaptic(joy));
		printf("haptic result: %d;", test_haptic(joy));
	}

// test_haptic function found here:
http://wiki.libsdl.org/moin.cgi/CategoryForceFeedback

========================
Output:

1 joysticks were found.
0 are hapitcs.
is haptic?: 1

then it crashes here:
SDL_Haptic *
SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
{
     /* ... */
      /* Check to see if joystick's haptic is already open */
    for (i = 0; SDL_haptics[i]; i++) {
     /* ... */


* SDL_haptics is a NULL Pointer in this context! *
Comment 1 Edgar Simo 2012-05-06 02:33:39 UTC
Created attachment 851 [details]
More defensive checks to make sure stuff works.

I recall that driver being buggy back in the day, but looking over the code there's a number of things being done wrong which I've fixed and it should now properly error out instead of crashing. Also make sure you initialize the haptic subsystem before using haptic commands (which I now more explicitly try to enforce).
Comment 2 Ryan C. Gordon 2013-07-12 22:15:36 UTC
(Sorry if you get a lot of copies of this email, we're touching dozens of bug reports right now.)

Tagging a bunch of bugs as target-2.0.0, Priority 2.

This means we're in the final stretch for an official SDL 2.0.0 release! These are the bugs we really want to fix before shipping if humanly possible.

That being said, we don't promise to fix them because of this tag, we just want to make sure we don't forget to deal with them before we bless a final 2.0.0 release, and generally be organized about what we're aiming to ship.

Hopefully you'll hear more about this bug soon. If you have more information (including "this got fixed at some point, nevermind"), we would love to have you come add more information to the bug report when you have a moment.

Thanks!
--ryan.
Comment 3 (disabled) Jørgen Tjernø 2013-07-14 19:09:55 UTC
Edgar, would you mind updating your patch to apply cleanly to todays master?
Comment 4 Edgar Simo 2013-07-14 19:45:58 UTC
Created attachment 1233 [details]
Updated version of the more defensive checks patch.

Didn't reformat most of the SDL_SetErrors, which should probably be another patch (remove trailing '.'). Seems to work fine on my linux machine.
Comment 5 Sam Lantinga 2013-07-27 05:47:28 UTC
Edgar, your patch is in, thanks!
http://hg.libsdl.org/SDL/rev/6d8fd70e1477

Rodrigo, if you grab the latest snapshot from here, and make sure you pass SDL_INIT_HAPTIC to SDL_Init(), does this fix the problem for you?
http://www.libsdl.org/tmp/SDL-2.0.zip
Comment 6 Rodrigo Cardoso 2013-07-31 00:16:43 UTC
I tested with that testhaptic program, and now it seems to at last fail gracefully, no crashes :)

the output:

1 Haptic devices detected.
Device: Wireless 360 Controller
   Supported effects [256 effects, 1 playing]:
      sine
      square
      triangle
      sawtoothup
      sawtoothdown
   Supported capabilities:
      gain
      autocenter
      status

Uploading effects
   effect 0: Sine Wave
UPLOADING EFFECT ERROR: Haptic: Unable to create effect: function call unsupported.

Aborting program execution.


The fact it is not working is probably a controller driver problem, the author mentioned it is buggy, but hey, no crashes, it seems to be fixed :)



[off]:
Does anyone have a wireless xbox 360 controller and a osx machine to test if it works for you?
I have no other mac compatible gamepad that reports itself as haptic , Can you recommend anyone?

Cheers!