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

haptic support on iOS #26

Closed
orangepascal opened this issue Sep 9, 2022 · 4 comments · Fixed by #32 or #33
Closed

haptic support on iOS #26

orangepascal opened this issue Sep 9, 2022 · 4 comments · Fixed by #32 or #33

Comments

@orangepascal
Copy link
Contributor

orangepascal commented Sep 9, 2022

Lost controller support in my games on iOS15 (and 14) and traced it back to this code:

        if (Foundation.getMajorSystemVersion() >= 14) try {
            hapticEngine = controller.getHaptics().createEngine(GCHapticsLocality.Default);
            hapticEngine.retain();
        } catch (Throwable t) {
            Gdx.app.error("Controllers", "Failed to create haptics engine", t);
        }

Tried various controllers, and I'm guessing they just don't have haptic support (or don't provide it to iOS).
And from the Apple documents it says that getHaptics() might return nil if not available.

So should this get a check first? Because right now the controller isn't created because it throws the error for the haptics engine, even tho the controller will work just fine (it does on iOS<14 when this code is skipped)

(for completeness, error given on ios15:
Controllers: Failed to create haptics engine
java.lang.NullPointerException
at com.badlogic.gdx.controllers.IosController.(IosController.java:83)
at com.badlogic.gdx.controllers.IosControllerManager.onControllerConnect(IosControllerManager.java:116)
at com.badlogic.gdx.controllers.IosControllerManager$1.invoke(IosControllerManager.java:89)
at com.badlogic.gdx.controllers.IosControllerManager$1.invoke(IosControllerManager.java:86)
at org.robovm.apple.gamecontroller.GCController$Notifications$1.invoke(GCController.java:49)
at org.robovm.apple.gamecontroller.GCController$Notifications$1.invoke(GCController.java:46)
at org.robovm.apple.foundation.NSNotificationCenter$$BlockMarshaler0.invoked(Unknown Source)
at org.robovm.apple.uikit.UIApplication.main(Native Method)
at org.robovm.apple.uikit.UIApplication.main(UIApplication.java:433)
at com.orangepixel.residual.IOSLauncher.main(IOSLauncher.java:35)
)

tested with a MadCatz mfi controller but also a standard PS4 - both work fine if running on iOS13

@MrStahlfelge
Copy link
Member

Yes, check might be needed - I only have an Xbox controller to test with so did not notice the problem.

@orangepascal
Copy link
Contributor Author

Wanted to do it myself, but ran into a bunch of version mismatches trying to build things (gradle,maven,jdk,androidsdk,etc) - and currently in a big game-update flow where things work, so don't want to update or change ANY versions right now :D

hopefully someone with contribution skills can do a quick fix for a nightly? wink wink, please,please

(think it's a matter of checking if controller.getHaptics() returns null before calling createEngine)

@orangepascal
Copy link
Contributor Author

Tested the fix on a local version of the library, and it works and makes sure all non-haptic supporting controllers don't break the whole controller support.

if (Foundation.getMajorSystemVersion() >= 14) try { if (controller.getHaptics()!=null) { hapticEngine = controller.getHaptics().createEngine(GCHapticsLocality.Default); hapticEngine.retain(); } } catch (Throwable t) { Gdx.app.error("Controllers", "Failed to create haptics engine", t); }

If someone more familiar with git+libgdx could push a proper code update so I don't mess things up that would be great :) For now I'll use my modified lib so I can push updates to my games.

@MrStahlfelge
Copy link
Member

It would have been enough when you had just opened a PR with the change. I just made the button click for you.

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