-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[rcore] Gamepad not working on macOS #3651
Comments
@NitroPlum Either way:
Edits: 1. added more information; 2. updated info, formatting. |
After GLFW, I also tried the SDL backend. Is there a way for me to fix the binding issue locally @ubkp ? |
Oh, another bit of info that may help. I did try in the browser examples on the Raylib site and both controllers work there. |
@NitroPlum Sure, create your own binds (you may want to take a look at SDL_GameControllerDB) and add it to your local
AFAIK, the web browser gamepad API is a completely different thing (ref1, ref2). Edit 1: AFAIK sometimes firmware updates end up changing the device GUID, which causes it to no longer match the DB. I could be wrong, but I think that happened to some Xbox controllers. Edit 2: Apparently you can even use Steam's Big Picture mode to generate binds these days (ref). |
I have similar problems. I am using the c# bindings of raylib on MacOSX 14.2.1 Sonoma and gamepad input is no longer working. Raylib detects the connected gamepads but does not trigger any button/ trigger/ axis functions. I have tested Xbox Elite Controller 2 & Xbox Series X Controller.
At same point it just stopped working for me.... The example I am using to test this all out works fine on windows (the gamepad is detected & the input is detected) I think the only thing I did was update the firmware on my elite controller but the other controller I did not update... I have tried to use custom bindings and bindings from SDL_GameControllerDB with the SetGamepadMappings function but it did not change anything. |
@SoloByte Thanks for reporting. Could you try with raylib latest master branch version? raylib 5.0 (November 2023) implemented a big redesign for desktop platforms and despite everything was carefully tested, some things could not work as expected. I don't have a macOS, neither those mentioned gamepads, I need help to fix this issue. |
@raysan5 All three are detected by my MacBook, all three work on windows, all three work with a gamepad tester. I have tested them with the raylib input gamepad example and they are detected and the input works (even when more than 1 is connected) but it seems that the triggers are not detected at all (Left/Right Trigger). The joystick axis work fine. I have tested it with my simple raylib cs gamepad tester project and the controllers are detected but no input is registered.
It would be helpful if someone could test this on a Mac with raylib, because I can only test it with raylib C# bindings. I will post my simple project here. It is possible that I am doing something wrong or missing a step.
|
@SoloByte I also cannot find any platform specific macos code in raylib. Maybe a newer version of GFLW will fix this. |
It seems this issue is specific to a binding, I'm afraid I'm closing it for raylib C side. |
I have a similar issue with plain C, on mac M1 (Sonoma.) On web, it works fine, but with this code, I only get the name, but no button-events, on native raylib 5.5: #include "raylib.h"
int main(void) {
InitWindow(320, 240, "gamepad test");
SetTargetFPS(60);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
char* gpText = "No gampepad";
for (int gamepad=0; gamepad < 5; gamepad++) {
if (IsGamepadAvailable(gamepad)) {
gpText = TextFormat("GP%d: %s", gamepad, GetGamepadName(gamepad));
for (int gamepadButton = GAMEPAD_BUTTON_UNKNOWN; gamepadButton <= GAMEPAD_BUTTON_RIGHT_THUMB; gamepadButton++) {
if (IsGamepadButtonDown(gamepad, gamepadButton)) {
DrawCircle((gamepadButton*17) + 9, 120, 8, RED);
} else {
DrawCircle((gamepadButton*17) + 9, 120, 8, GRAY); }
}
}
}
DrawText(gpText, 10, 10, 10, BLACK);
EndDrawing();
}
CloseWindow();
return 0;
} I tested with 2 controllers: official PS5 controller, paired over bluetooth
PXN-P50S, connected over bluetooth, as "Pro Controller"
I am happy to test anything you like. I have 2 macs for testing (intel and M1.) Update, after re-pairing a couple times, I got the PS5 controller to work, but not the PXN-P50S: UpdateI made a similar tester in GLFW (3.4) and got similar results. #include <GLFW/glfw3.h>
#include <stdio.h>
#ifdef EMSCRIPTEN
#include <emscripten.h>
#endif
void joystick_connect_callback(int jid, int event) {
if (event == GLFW_CONNECTED) {
printf("connected: %d: %s\n", jid, glfwGetJoystickName(jid));
} else if (event == GLFW_DISCONNECTED){
printf("disconnected: %d: %s\n", jid, glfwGetJoystickName(jid));
}
}
GLFWwindow *window = NULL;
void mainLoop() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
for (int jid = GLFW_JOYSTICK_1; jid<GLFW_JOYSTICK_4;jid++) {
if (glfwJoystickPresent(jid)) {
int count = 0;
const unsigned char* buttons = glfwGetJoystickButtons(jid, &count);
for (int b=0;b<count;b++) {
if (buttons[b]) {
printf("%d %u: DOWN\n", jid, b);
} else {
printf("%d %u: UP\n", jid, b);
}
}
}
}
}
int main() {
if (!glfwInit()) {
return 1;
}
window = glfwCreateWindow(320, 240, "gamepad tester", NULL, NULL);
if (!window) {
glfwTerminate();
return 1;
}
glfwMakeContextCurrent(window);
glfwSetJoystickCallback(joystick_connect_callback);
for (int jid = GLFW_JOYSTICK_1; jid<GLFW_JOYSTICK_4;jid++) {
if (glfwJoystickPresent(jid)) {
printf("present: %d: %s\n", jid, glfwGetJoystickName(jid));
}
}
#ifdef EMSCRIPTEN
emscripten_set_main_loop(&mainLoop, 0, 1);
#else
while (!glfwWindowShouldClose(window)) {
mainLoop();
}
#endif
glfwDestroyWindow(window);
glfwTerminate();
return 0;
} Both were seen initially, but only PS5 updated it's buttons. Like, I saw this, with some buttons pressed on both:
|
That makes sense, but the weird thing is it does work correctly for a short-while in GLFW, when it first pairs. Also, I thought those mappings were just for named-buttons, but without them it will still send whatever button-int the controller sends. Maybe I am misunderstanding that part. I setup this code so I could see what was happening a bit better, without any other layers (just glfw.) For about 4 seconds after it pairs, it works fine, and the buttons are mapped correctly. |
Yep, I can setup a raylib tester with
Yeh, and this all works in Linux, too, so I think it's some mac-specific bug. It may just be that joystick, or Mac's handling of switch controllers, I am not sure. |
Ok, I did a bunch of testing here. The glfw demo needs more work, It's kinda complicated to do graphics on web and native with same code! I keep getting hung up on different deps I need for each target, and finding a balance has been a bit tricky. I settled on a very old version of glsl, so i need to work out the rest of code for that. I also need to flesh out the plain SDL demo a bit more, and I want to also try manually loading a new gamepad-map on glfw to see if that helps (although my understanding is it shouldn't matter, and it will return button-numbers without it, which are not mapped to correct position for xbox controller, but otherwise work.) Here is what I know so far:
I'm going to try to finish all the tests, just because I like having the test-suite, and I have been thinking about evaluating input & graphics on glfw/sdl anyway (for my game engine) but I think I can confidently call it, in terms of raylib: glfw has issues with this (otherwise working) controller on mac, but SDL is ok. It seems like a GLFW problem, not raylib, since plain glfw has issues, but maybe something we should track and try to help with (since it effects raylib users on mac, and is probably not specific to this 1 gamepad.) |
This particular controller does not work over USB here, at least that I could figure out. The manual indicates it should work, but it never shows up in OSX settings panel, unless I pair with bluetooth. This controller is also fine over bluetooth with SDL and several other apps (browser, steam, etc) and PS5 controller is ok over bluetooth with everything (even native glfw.) I think it's a good troubleshooting step, but the controller may just not work that way, even when all is well. |
Reopening for further review. |
I think so too. The plain GLFW thing is especially weird, and I found it kinda by accident. If I do this it works fine for about 4 seconds, then stops:
I will try this out, later. I think would like to test with raylib's copy of glfw, because my plain glfw demo is in a bit of a broken state (trying to get it working on web & native with same code.) Maybe I should drop web target, since that seems to work ok, from other tests, or just use the raylib-wrapped demo, so it can all run from same simple code. |
yep, I mention it only as a contrast like "this controller works in this other thing" similar to native SDL testing. Chrome seems to work great with this controller, in raylib, and out.
Interesting. That does seem possibly related. |
Ok, yeh, I am going to make a decision about the demos, to stay in scope, and not get overwhelmed with all the stuff needed to get not-as-helpful demos running:
Playing with this really makes me appreciate raylib & sdl, and how much they abstract away! |
yeh, I am no expert, but it definitely seems like a timing/threading thing to me because of the works-for-4-seconds thing. I was mistyping earlier, though ("glsl" when I meant "glfw") I think I fried my brain a lil going deep on this stuff :) and also I am dyslexic and mix up similar words a lot. I don't think the prob is specific to glsl/3d, as it seems to happen in glfw with or without using any opengl stuff. |
ok, I did this: void _glfwTerminateJoysticksCocoa(void)
{
printf("trying to terminate joy\n");
for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{
if (_glfw.joysticks[jid].connected)
closeJoystick(&_glfw.joysticks[jid]);
}
if (_glfw.ns.hidManager)
{
CFRelease(_glfw.ns.hidManager);
_glfw.ns.hidManager = NULL;
printf("releasing joy\n");
}
} on plain glfw, it outputs both lines when I close window:
but not before. |
Based on name/platform I narrowed the map lines down to these: const char* mappings = "030000007e0500000920000000000000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Mac OS X,\
030000007e0500000920000001000000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Mac OS X,\
030000007e0500000920000010020000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,platform:Mac OS X,\
050000007e05000009200000ff070000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,platform:Mac OS X,";
int mapstatus = SetGamepadMappings(mappings);
TraceLog(LOG_INFO, "mapping: %d", mapstatus); I get same issue, with It still shows "Pro Controller" so mapping might not be working right. I also tried adding same lines to mappings.h in glfw, with same results (wrong name, etc.) Running a tester program, I got this from SDL2:
Searching through the existing mapping these are already in there, and have "correct" name:
and these were not in there:
Nothing seems to pick up these mappings, though. Like I also added this: const char* mappings = "0300d71f7e0500000920000001006803,DK Switch Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b10,x:b2,y:b3,platform:Mac OS X,";
int mapstatus = SetGamepadMappings(mappings);
TraceLog(LOG_INFO, "JS: mapping: %d", mapstatus); and for both SDL & GLFW, it uses names that are not "DK Switch Controller" |
Hi, Tried this example . Works on web with no issues. But same code run under Raylib 5.5 on Mac not working. It found properly controller, but neither buttons nor axis are working. |
@MikeshCZ would you mind compiling/running this tester (it has instructions at top for compiling, for mac/linux with SDL2 installed, but lemme know if you need help.) This will give us the SDL id/name which might help narrow down the issue, and it also helps identify that it's not just my cheapo controller, but other popular controllers, that work fine in SDL. |
@konsumer This is returned value from your code:
|
Please, before submitting a new issue verify and check:
Issue description
Gamepad input not working. I tried 2 different controllers.
Environment
MacOSX Ventura on an M2 Mac.
Issue Screenshot
Can't really show this.
Code Example
Provide minimal reproduction code to test the issue. Please, format the code properly and try to keep it as simple as possible, just focusing on the experienced issue.
The text was updated successfully, but these errors were encountered: