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 3659 - Haptic feedback no longer works in OS X release builds
Summary: Haptic feedback no longer works in OS X release builds
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: haptic (show other bugs)
Version: 2.0.5
Hardware: x86 Mac OS X (All)
: P2 blocker
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.6
Depends on:
Blocks:
 
Reported: 2017-05-29 19:51 UTC by RustyM
Modified: 2019-01-06 16:22 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description RustyM 2017-05-29 19:51:17 UTC
Haptic feedback no longer works when built with modern versions of Xcode. Haptic feedback works normally in debug builds, but release builds without a debugger attached no longer work.

Xcode 7.2.1 and previous versions work correctly.
Xcode 7.3 and onward all exhibit this issue.
Comment 1 Ryan C. Gordon 2017-06-06 19:37:26 UTC
This works here:

- Get the latest SDL sources
- Open Xcode/SDL/SDL.xcodeproj
- Hit Apple-B to build it.
- Quit Xcode
- Open Xcode/SDLtest/SDLtest.xcodeproj
- Hit Apple-B to build.
- Find testrumble in the list of products
- Right click, "Show in Finder"
- Run it, feel controller vibrate.

Am I doing something wrong? This was Xcode 8.3.2, using a wired Xbox360 controller and the 0.16.5 drivers from https://github.com/360Controller/360Controller/releases

--ryan.
Comment 2 RustyM 2017-06-06 20:41:40 UTC
Ahh, yes that test works correctly for me too. I’m remembering the specifics of this bug as I dig deeper. The test uses the “SDL_HapticRumblePlay”, But I'm have specific issues "SDL_HapticEffect.type":


SDL_HAPTIC_LEFTRIGHT
Works on PC, but has NEVER worked on Mac. (Really just want SDL_HAPTIC_LEFTRIGHT working on Mac)

SDL_HAPTIC_CUSTOM
I’m using this to get the SDL_HAPTIC_LEFTRIGHT functionality working on Mac. This is what was previously working on in Xcode 7.2.1 and below and stopped after Xcode 7.3 on up.

SDL_HAPTIC_CONSTANT
Works on Mac and PC, but can’t control the Xbox 360 motors separately.


I’m also running Xcode 8.3.2 and the 0.16.5 drivers from https://github.com/360Controller/360Controller/releases
Comment 3 Sam Lantinga 2017-06-07 18:45:59 UTC
Can you post the code you're using with SDL_HAPTIC_CUSTOM?

Thanks!
Comment 4 RustyM 2017-06-08 12:24:57 UTC
Sure! Pasting it below. Let me know if any of this isn't clear.


typedef enum {
    kHapticEffectShoot,
    kHapticEffectDamage,
    kHapticEffectDeath,
    kHapticEffectShort
} HapticEffect;

struct HapticStruct {
    SDL_Haptic *haptic;
    HapticType hapticType;
};


int InputPlayer::createHapticEffect(HapticEffect effectType)
{
    SDL_HapticEffect effect;
    int id = -1;
    memset( &effect, 0, sizeof(SDL_HapticEffect) );
    
    effect.type = SDL_HAPTIC_CUSTOM;
    effect.custom.direction.type = SDL_HAPTIC_POLAR;
    effect.custom.direction.dir[0] = 0;
    effect.custom.length = 5000;
    effect.custom.attack_length = 0;
    effect.custom.fade_length = 0;
    effect.custom.channels = 2;
    effect.custom.samples = 2;
    effect.custom.period = 0;
    
    switch (effectType) {
        case kHapticEffectShoot: {
            Uint16 data[] = {0, 32767}; // Small Motor
            effect.custom.data = data;
            break; }
        case kHapticEffectDamage: {
            Uint16 data[] = {0, 25700}; // Small Motor
            effect.custom.data = data;
            break; }
        case kHapticEffectDeath: {
            Uint16 data[] = {32767, 32767}; // Both Motors
            effect.custom.data = data;
            break; }
        case kHapticEffectShort: {
            Uint16 data[] = {32767, 32767}; // Both Motors
            effect.custom.data = data;
            break; }
    }
    
    id = SDL_HapticNewEffect( hapticStruct.haptic, &effect );
    
    if (id < 0) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
    
    return id;
}


void InputPlayer::playHapticEffect(HapticEffect effectType)
{
    if (hapticStruct.haptic == nullptr) return;
    if (hapticStruct.hapticType == kHapticType_NONE) return;

    int effectID = -1;
    switch (effectType) {
        case kHapticEffectShoot:    rumbleTimer = 0.175f; break;
        case kHapticEffectDamage:   rumbleTimer = 0.35f; break;
        case kHapticEffectDeath:    rumbleTimer = 0.7f; break;
        case kHapticEffectShort:    rumbleTimer = 0.25f; break;
    }
    
    if (prevEffectID > -1) SDL_HapticDestroyEffect(hapticStruct.haptic, prevEffectID);
    effectID = createHapticEffect(effectType);
    prevEffectID = effectID;
    
    if (effectID != -1) SDL_HapticRunEffect(hapticStruct.haptic, effectID, 1);
}


// Stop Rumble manually
void InputPlayer::update()
{
    if (rumbleTimer > 0) {
        rumbleTimer -= 0.0166666667f;
        if (rumbleTimer <= 0) {
            stopRumble();
        }
    }
}

void InputPlayer::stopRumble()
{
    if (hapticStruct.hapticType == kHapticType_NONE) return;
    SDL_HapticStopAll(hapticStruct.haptic);
}
Comment 5 Ryan C. Gordon 2017-08-09 05:38:15 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.6.

This means we're in the final stretch for an official SDL 2.0.6 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.6 release, and generally be organized about what we're aiming to ship. After some debate, we might just remove this tag again and deal with it for a later release.

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 6 RustyM 2019-01-06 16:22:14 UTC
The new controller HIDAPI in 2.0.9 provides haptic functionality without using the haptic api. SDL_GameControllerRumble() seems to work properly on new versions of Xcode, so, I think this bug can be closed.