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

Xbox One Controller not working on MacOS cpp builds #3197

Open
increpare opened this issue Jul 3, 2024 · 8 comments
Open

Xbox One Controller not working on MacOS cpp builds #3197

increpare opened this issue Jul 3, 2024 · 8 comments

Comments

@increpare
Copy link

increpare commented Jul 3, 2024

Version/Build: information (checked for all listed platforms):

  • Haxe version: 4.3.4 (all haxe builds were made with the -debug flag)
  • Flixel version: 5.8.0
  • OpenFL version: 9.3.3
  • Lime version: 8.1.2
  • SDL version (for SDL test): 2.30.1
  • Dead Cells version (for heaps.io test): v34 (2023-06-20-ffcb38d13-15-Steam)
  • Xbox controler firmware version: 5.21.3241.0
  • Operating system: MacOS: Sonoma 14.5, Windows: 10 22H2
  • Browser: (MacOS: Chrome Version 126.0.6478.127 (Offizieller Build) (arm64). Windows: Edge 126.0.2592.81 (Official build) (64-bit). Friend's MacBook: Vivialdi (chrome-based browser) 6.8.3381.46 (Stable channel) (arm64) )
  • Affected targets: MacOS cpp

Brief description:

Controller support isn't working for me for cpp flixel builds on MacOS (ok in browser). Works on windows fine.

Long description:

I have made five test programs as part of trying to verify this bug:
FLIX - FlixelControllerTest ( Uses FlxGamepad. Opens the Flixel debugger at launch and logs when the left stick is moved or the a button is pressed ). Bildschirmfoto 2024-07-03 um 14 33 08

LIME - LimeControllerTest ( Uses lime.ui.Gamepad. This traces all controller events to the console ). Bildschirmfoto 2024-07-03 um 14 33 43

SDL - SDL_Test (C example with SDL2. Visualises input in a window, and outputs to console. Should be further along the dependency chain still I think. It only runs for me from within xcode 🤷 ). Bildschirmfoto 2024-07-03 um 14 34 10

JS - JsWebExample (basic html/js Controller-API example, displays all inputs in browser window ). Bildschirmfoto 2024-07-03 um 14 34 37

DC - Dead Cells (I just wanted a Haxe example in a different engine, in this case Dead Cells, that is made with heaps.io - I briefly tried but wasn't able to get https://heaps.io/samples/pad.html compiling on my computer).

Source Code:

The source code for FLIX/LIME/SDL/JS examples is in this repo:

https://github.com/increpare/ControllerBugTestSuite

For reference, because it pertains the most, here's the core of the Flixel source code example:

import flixel.FlxG;
import flixel.FlxState;
import flixel.input.gamepad.FlxGamepad;

class PlayState extends FlxState
{
    public function onDeviceConnected(gp:FlxGamepad){
        FlxG.log.add("A gamepad has been connected!");
    }

    override public function create():Void 
    {
        super.create();
        FlxG.debugger.visible=true;
        FlxG.gamepads.deviceConnected.add(onDeviceConnected);
    }

    override public function update(elapsed:Float):Void 
    {
        super.update(elapsed);

        // Important: can be null if there's no active gamepad yet!
        var gamepad:FlxGamepad = FlxG.gamepads.lastActive;
        if (gamepad != null)
        {
            updateGamepadInput(gamepad);
        }
    }

    function updateGamepadInput(gamepad:FlxGamepad):Void
    {
        //trace currently pressed buttons
        if (gamepad.pressed.A)
        {
            FlxG.log.add("The A button has been pressed.");
        }
		
        if (gamepad.analog.justMoved.LEFT_STICK_X)
        {
            FlxG.log.add("The x axis of the left analog stick of the controller has been moved.");
        }
    }
}

Testing

I test them on the following platforms:

**MB1**: My MacBook 
**MB2**: My friend's MacBook
**WIN**: My windows machine

I test them with the following builds:

**SO**: standalone
**BO**: browser

Setup:

  • For all the examples except for Dead-Cells, I made sure steam was closed so as to not interfere with inputs.
  • On MacOS I verified that the controller was connected via the bluetooth settings, and present in the controller settings page in the MacOS system settings. Bildschirmfoto 2024-07-03 um 14 41 24
  • On MacOS, I also made sure, in the system settings area, that input monitoring was enabled for Chrome and Visual Studio Code. (I've tried adding the apps produced by openfl to the input monitoring permissions list, but it just refuses...). Bildschirmfoto 2024-07-03 um 14 42 39
  • All haxe projects were build with "openfl test html5/cpp -debug"
  • I had tested with 4 different controllers, each with different compatibilities, in wired and wireless modes, but for this report I'm using only the widely-supported Xbox One controller in wireless mode (what MacOS officially supports).

Results

Firstly, the results on windows, where everything should work (Y=controller input works, N = controller input doesn't work):

WIN-SO-FLIX:	Y
WIN-SO-LIME:	Y
WIN-SO-DC:	Y

WIN-BR-FLIX:	Y
WIN-BR-LIME:	Y
WIN-BR-JS:	Y

Then on my MacBook

MB1-SO-FLIX:	N
MB1-SO-LIME:	N
MB1-SO-SDL:	Y
MB1-SO-DC:	Y

MB1-BR-FLIX:	Y
MB1-BR-LIME:	Y
MB1-BR-JS:	Y

Then on my friend's MacBook (Macs are so weird with permissions it was worth double-checking on another computer for differences)

MB2-SO-FLIX:	N

MB2-BR-FLIX:	Y
MB2-BR-LIME:	Y
MB2-BR-JS:	Y
@Geokureli
Copy link
Member

Geokureli commented Jul 3, 2024

Are all of your tests done via bluetooth or did you also try physically connecting them? I wanna say in the past I've had trouble using controllers on my mac with BT even outside of flixel testing and also on my browser, I'll give the suite a try. I don't have an xbox controller but I have PS4 and Switch Pro controllers.

This is likely something that will need to be fixed in lime, but its never a bad idea to start here

Edit: I'm not familiar with running SDL projects, should I be using Xcode directly for that?

@increpare
Copy link
Author

increpare commented Jul 3, 2024

Are all of your tests done via bluetooth or did you also try physically connecting them?

@Geokureli Hi! I was not able to get either Xbox or Xbox Elite controller working at all in wired usb mode (I even installed the open source drives that I used to use https://github.com/360Controller/360Controller, but it didn't make a difference). All the (slightly older versions of the tests I used yesterday) failed on MacOS. On Windows in my main project I haven't had any problems with wired Xbox controllers (nor with my wired 8BitDo controller).

I just tried the 8BitDo controller in wireless mode and it looks to work wirelessly.

It is detected by MacOS as a gamepad:

Bildschirmfoto 2024-07-03 um 16 42 29

And here are the test results:

MB1-SO-FLIX-8BITDO:	Y
MB1-SO-LIME-8BITDO:	Y
MB1-SO-SDL-8BITDO:	Y
MB1-SO-DC-8BITDO:	Y

MB1-BR-FLIX-8BITDO:	Y
MB1-BR-LIME-8BITDO:	Y
MB1-BR-JS-8BITDO:	Y

(note, I accidentally ran the SO tests with Steam running in the background, which technically breaks my protocol, but my controller just ran out of battery...)

This is likely something that will need to be fixed in lime, but its never a bad idea to start here

Should I just duplicate the bug report to lime? I could remove the flixel-specific examples to save them some effort.

@increpare
Copy link
Author

increpare commented Jul 3, 2024

Edit: I'm not familiar with running SDL projects, should I be using Xcode directly for that?

I used Xcode (which I'm also not so familiar with anymore) - I had followed the http://lazyfoo.net tutorial - it should be a case of opening up the linked .xcodeproj file and hitting build.

Bildschirmfoto 2024-07-03 um 17 14 00

However, maybe I've messed things up slightly and Xcode has some global paths set or the like. To help verify that things are okay, the opened project should have this structure in XCode (I guess the products folder only appears when you actually do a build).

Bildschirmfoto 2024-07-03 um 17 14 38

I'm very happy to try prepare a different SDL build if you can specific a different process/set of build tools you'd prefer!

@Geokureli
Copy link
Member

it should be a case of opening up the linked .xcodeproj file and hitting build.

I'll try that, thanks

I just tried my PS4 with the lime and flixel projects and it seems to work, wirelessly.
Screenshot 2024-07-03 at 10 12 28 AM
Screenshot 2024-07-03 at 10 22 10 AM

One of your images shows a PS4 controller was connected, but you never mention whether that was tested with these projects, so I assume all your controllers had the same results for you. I still plan to try my switch cons and I can probably borrow an Xbox controller. I'll also try xcode after it finishes updating

@increpare increpare changed the title Controller not working on MacOS cpp builds Xbox Controller not working on MacOS cpp builds Jul 4, 2024
@increpare increpare changed the title Xbox Controller not working on MacOS cpp builds Xbox One Controller not working on MacOS cpp builds Jul 4, 2024
@increpare
Copy link
Author

increpare commented Jul 4, 2024

Thanks for having a look!

Hmm, given your test results, and my test results, I wonder if it's to do with controller mappings (SDL_gamecontrollerdb.h).

I couldn't find lime 8.1.2 on GitHub, but lime 8.2.0-dev relies on SDL 2.0.12 according to this page, released on 11.03.2020.

I see then this issue, Added mapping for Xbox One S controller with newer firmware on macOS - submitted to the SDL 2.0.22 release branch (there are of course more recent bugs relating to xbox controllers and MacOS).

I think SDL loads controller mappings of its own, but lime loads some here:
https://github.com/openfl/lime/blob/b99eff85c1a559a010d425be789b266b085b7d9c/src/lime/ui/Window.hx#L231

In the lime test, I tried calling this at the start of Main::init() to load the most recent mappings:

var mappings=[
	//https://github.com/libsdl-org/SDL/blob/9d47daef0a674b06f97be383f67b6e7bf406f41b/src/joystick/SDL_gamepad_db.h#L463
	"030000005e040000200b000011050000,Xbox Wireless Controller,platform:Mac OS X,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
	"030000005e040000e002000000000000,Xbox Wireless Controller,platform:Mac OS X,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
	"030000005e040000e002000003090000,Xbox Wireless Controller,platform:Mac OS X,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
	"030000005e040000ea02000000000000,Xbox Wireless Controller,platform:Mac OS X,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
	"030000005e040000fd02000003090000,Xbox Wireless Controller,platform:Mac OS X,a:b0,b:b1,back:b16,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b15,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",			
];
Gamepad.addMappings(mappings);

But it doesn't make a difference. (I also tried moving it to before Main::new's call to super, in case you have to call it very early, but that made no difference).

I also tried with lines 1072-1096 from the SDL_GameControllerDB file, but it didn't work either.

====

One of your images shows a PS4 controller was connected, but you never mention whether that was tested with these projects, so I assume all your controllers had the same results for you.

They had very diverse and somewhat confusing results in early and more informal tests (though the Xbox Elite had the same behaviour as the regular Xbox one controller). For the bug report I wanted to focus on one controller and be really certain I wasn't talking nonsense.

But now I have a protocol established I can try them again. Indeed, see the 8BitDo results in a comment above - it works fine wirelessly on Mac. The PS controller is a friend's. I'll try at the next possibility, and report back (probably within the next week :) ).

@increpare
Copy link
Author

Checking out a PS5 controller in bluetooth-mode:

MB1-SO-FLIX-PS5-BT:	N
MB1-SO-LIME-PS5-BT:	N
MB1-SO-SDL-PS5-BT:	Y
MB1-SO-DC-PS5-BT:	Y

MB1-BR-FLIX-PS5-BT:	Y
MB1-BR-LIME-PS5-BT:	Y
MB1-BR-JS-PS5-BT:	Y

(Doubting my sanity, I double checked and the 8BitDo bluetooth controller I tried before still works in the bluetooth test cases where the PS5 controller fails... ).

Checking it out when it's plugged in via a cable:

MB1-SO-FLIX-PS5-USB:	N
MB1-SO-LIME-PS5-USB:	N
MB1-SO-SDL-PS5-USB:	Y
MB1-SO-DC-PS5-USB:	Y

MB1-BR-FLIX-PS5-USB:	Y
MB1-BR-LIME-PS5-USB:	Y
MB1-BR-JS-PS5-USB:	Y

@Geokureli You're on MacOS Somona (V14) right? x86 or ARM? I don't think I've done too much violence to my operating system that I'd expect to have different results for the same hardware. 😅

@Geokureli
Copy link
Member

You're on MacOS Somona (V14) right? x86 or ARM?

Ventura 13.6.7 x86 (intel is x86, right?)

I'm away from home for the next 2 weeks and i wasn't able to borrow a friend's xbox controller, plus it was a 360 controller, anyway. I may just buy one and return it, if the policy allows it

@increpare
Copy link
Author

Ventura 13.6.7 x86 (intel is x86, right?)
Yip. Oh dear, who knows what difference might be producing such different results ^^

(I'm more than happy to sponsor the purchase of an xbox controller if you like - just email me the amount at [email protected] :) )

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

2 participants