Skip to content

Commit

Permalink
fix enumeration, possible memory explosion
Browse files Browse the repository at this point in the history
  • Loading branch information
jcm93 committed Feb 20, 2025
1 parent 47192eb commit ec41b10
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
19 changes: 9 additions & 10 deletions cmake/finders/FindSDL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,18 @@ macro(SDL_set_soname)
unset(_result)
endmacro()

find_library(
SDL_LIBRARY
NAMES SDL3 SDL3-3.0.0 SDL3-3.0
HINTS ${PC_SDL_LIBRARY_DIRS}
PATHS ${CMAKE_SOURCE_DIR}/.deps /usr/lib /usr/local/lib
DOC "SDL location"
)

find_path(
SDL_INCLUDE_DIR
NAMES SDL.h SDL3/SDL.h
HINTS ${PC_SDL_INCLUDE_DIRS}
HINTS ${PC_SDL_INCLUDE_DIRS} ${SDL_LIBRARY}/..
PATHS ${CMAKE_SOURCE_DIR}/.deps /usr/include /usr/local/include
DOC "SDL include directory"
# "$<$<PLATFORM_ID:Darwin>:NO_DEFAULT_PATH>"
Expand All @@ -82,15 +90,6 @@ else()
set(SDL_VERSION 0.0.0)
endif()

find_library(
SDL_LIBRARY
NAMES SDL3 SDL3-3.0.0 SDL3-3.0
HINTS ${PC_SDL_LIBRARY_DIRS}
PATHS ${CMAKE_SOURCE_DIR}/.deps /usr/lib /usr/local/lib
DOC "SDL location"
# "$<$<PLATFORM_ID:Darwin>:NO_DEFAULT_PATH>"
)

if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
set(SDL_ERROR_REASON "Ensure that ares-deps are provided as part of CMAKE_PREFIX_PATH.")
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
Expand Down
2 changes: 0 additions & 2 deletions cmake/macos/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ function(_bundle_dependencies target)

if(is_system_framework OR is_xcode_framework)
continue()
elseif(is_framework)
file(REAL_PATH "../../.." library_location BASE_DIRECTORY "${imported_location}")
elseif(_required_macos VERSION_GREATER CMAKE_OSX_DEPLOYMENT_TARGET)
continue()
elseif(NOT library_type STREQUAL "STATIC_LIBRARY")
Expand Down
21 changes: 16 additions & 5 deletions ruby/input/joypad/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,26 @@ struct InputJoypadSDL {
}
joypads.reset();
int num_joysticks;
SDL_GetJoysticks(&num_joysticks);
for(u32 id : range(num_joysticks)) {
SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks);
for(int i = 0; i < num_joysticks; i++) {
SDL_JoystickID id = joysticks[i];
Joypad jp;
jp.id = id;
jp.handle = SDL_OpenJoystick(jp.id);
if(!jp.handle) {
const char *err = SDL_GetError();
print("Error opening SDL joystick id ", id, ": ", err);
continue;
}

u32 axes = SDL_GetNumJoystickAxes(jp.handle);
u32 hats = SDL_GetNumJoystickHats(jp.handle) * 2;
u32 buttons = SDL_GetNumJoystickButtons(jp.handle);
s32 axes = SDL_GetNumJoystickAxes(jp.handle);
s32 hats = SDL_GetNumJoystickHats(jp.handle) * 2;
s32 buttons = SDL_GetNumJoystickButtons(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_GetJoystickVendor(jp.handle);
u16 pid = SDL_GetJoystickProduct(jp.handle);
Expand Down

0 comments on commit ec41b10

Please sign in to comment.