Skip to content

Commit

Permalink
ruby: SDL2 input fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
jcm93 committed Feb 20, 2025
1 parent 7a5174a commit 6c1efb8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ruby/input/joypad/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,20 @@ struct InputJoypadSDL {
Joypad jp;
jp.id = id;
jp.handle = SDL_JoystickOpen(jp.id);
if(!jp.handle) {
const char *err = SDL_GetError();
print("Error opening SDL joystick id ", id, ": ", err);
continue;
}

u32 axes = SDL_JoystickNumAxes(jp.handle);
u32 hats = SDL_JoystickNumHats(jp.handle) * 2;
u32 buttons = SDL_JoystickNumButtons(jp.handle);
s32 axes = SDL_JoystickNumAxes(jp.handle);
s32 hats = SDL_JoystickNumHats(jp.handle) * 2;
s32 buttons = SDL_JoystickNumButtons(jp.handle);
if(axes < 0 || hats < 0 || buttons < 0) {
const char *err = SDL_GetError();
print("Error retrieving SDL joystick information for device ", jp.handle, " at index ", id, ": ", err);
continue;
}

u16 vid = SDL_JoystickGetVendor(jp.handle);
u16 pid = SDL_JoystickGetProduct(jp.handle);
Expand Down

0 comments on commit 6c1efb8

Please sign in to comment.