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

SDL_JoystickGetAttached sets error "Joystick hasn't been opened yet", but SDL_GameControllerGetAttached is silent #5008

Closed
AntTheAlchemist opened this issue Nov 26, 2021 · 4 comments
Assignees
Milestone

Comments

@AntTheAlchemist
Copy link
Contributor

AntTheAlchemist commented Nov 26, 2021

As title. Why does one the JoystickGetAttached behave differently to the GameControllerGetAttached?

This code will trigger it:

SDL_JoystickGetAttached(SDL_JoystickFromInstanceID(SDL_JoystickGetDeviceInstanceID(0)));

Have at least 1 joystick plugged in. The error is triggered by SDL_JoystickGetAttached(). It's perfectly legal to get an instance ID before opening a joystick, and then get a joystick before it's opened with said ID, then check if that joystick is opened. There's no SDL_JoystickIsOpen(), so this is the only way I can do it. This works silently with SDL_GameControllerGetAttached(), so the different behaviour must be a bug.

@flibitijibibo
Copy link
Collaborator

I imagine this is why it does that: https://github.com/libsdl-org/SDL/blob/main/src/joystick/SDL_gamecontroller.c#L2342-L2343

If you change it to something like (gamecontroller == NULL) ? NULL : gamecontroller->joystick it will probably emit the same message.

@slouken slouken self-assigned this Nov 26, 2021
@slouken slouken added this to the 2.0.18 milestone Nov 26, 2021
@AntTheAlchemist
Copy link
Contributor Author

AntTheAlchemist commented Nov 26, 2021

Thanks guys.

To be pedantic and tidy, we can now safely remove

    if (!gamecontroller)
        return SDL_FALSE;

from SDL_GameControllerGetAttached().

@slouken
Copy link
Collaborator

slouken commented Nov 26, 2021

No, it would crash if we did that. :)

@AntTheAlchemist
Copy link
Contributor Author

AntTheAlchemist commented Nov 26, 2021

No, it would crash if we did that. :)

It won't now, because SDL_JoystickGetAttached() checks for null :P [delete delete delete]

Okay, yes it will crash, ignore me lol

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

3 participants