Skip to content

Commit ec41b10

Browse files
committed
fix enumeration, possible memory explosion
1 parent 47192eb commit ec41b10

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

Diff for: cmake/finders/FindSDL.cmake

+9-10
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,18 @@ macro(SDL_set_soname)
6464
unset(_result)
6565
endmacro()
6666

67+
find_library(
68+
SDL_LIBRARY
69+
NAMES SDL3 SDL3-3.0.0 SDL3-3.0
70+
HINTS ${PC_SDL_LIBRARY_DIRS}
71+
PATHS ${CMAKE_SOURCE_DIR}/.deps /usr/lib /usr/local/lib
72+
DOC "SDL location"
73+
)
74+
6775
find_path(
6876
SDL_INCLUDE_DIR
6977
NAMES SDL.h SDL3/SDL.h
70-
HINTS ${PC_SDL_INCLUDE_DIRS}
78+
HINTS ${PC_SDL_INCLUDE_DIRS} ${SDL_LIBRARY}/..
7179
PATHS ${CMAKE_SOURCE_DIR}/.deps /usr/include /usr/local/include
7280
DOC "SDL include directory"
7381
# "$<$<PLATFORM_ID:Darwin>:NO_DEFAULT_PATH>"
@@ -82,15 +90,6 @@ else()
8290
set(SDL_VERSION 0.0.0)
8391
endif()
8492

85-
find_library(
86-
SDL_LIBRARY
87-
NAMES SDL3 SDL3-3.0.0 SDL3-3.0
88-
HINTS ${PC_SDL_LIBRARY_DIRS}
89-
PATHS ${CMAKE_SOURCE_DIR}/.deps /usr/lib /usr/local/lib
90-
DOC "SDL location"
91-
# "$<$<PLATFORM_ID:Darwin>:NO_DEFAULT_PATH>"
92-
)
93-
9493
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
9594
set(SDL_ERROR_REASON "Ensure that ares-deps are provided as part of CMAKE_PREFIX_PATH.")
9695
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")

Diff for: cmake/macos/helpers.cmake

-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ function(_bundle_dependencies target)
113113

114114
if(is_system_framework OR is_xcode_framework)
115115
continue()
116-
elseif(is_framework)
117-
file(REAL_PATH "../../.." library_location BASE_DIRECTORY "${imported_location}")
118116
elseif(_required_macos VERSION_GREATER CMAKE_OSX_DEPLOYMENT_TARGET)
119117
continue()
120118
elseif(NOT library_type STREQUAL "STATIC_LIBRARY")

Diff for: ruby/input/joypad/sdl.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,26 @@ struct InputJoypadSDL {
9090
}
9191
joypads.reset();
9292
int num_joysticks;
93-
SDL_GetJoysticks(&num_joysticks);
94-
for(u32 id : range(num_joysticks)) {
93+
SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks);
94+
for(int i = 0; i < num_joysticks; i++) {
95+
SDL_JoystickID id = joysticks[i];
9596
Joypad jp;
9697
jp.id = id;
9798
jp.handle = SDL_OpenJoystick(jp.id);
99+
if(!jp.handle) {
100+
const char *err = SDL_GetError();
101+
print("Error opening SDL joystick id ", id, ": ", err);
102+
continue;
103+
}
98104

99-
u32 axes = SDL_GetNumJoystickAxes(jp.handle);
100-
u32 hats = SDL_GetNumJoystickHats(jp.handle) * 2;
101-
u32 buttons = SDL_GetNumJoystickButtons(jp.handle);
105+
s32 axes = SDL_GetNumJoystickAxes(jp.handle);
106+
s32 hats = SDL_GetNumJoystickHats(jp.handle) * 2;
107+
s32 buttons = SDL_GetNumJoystickButtons(jp.handle);
108+
if(axes < 0 || hats < 0 || buttons < 0) {
109+
const char *err = SDL_GetError();
110+
print("Error retrieving SDL joystick information for device ", jp.handle, " at index ", id, ": ", err);
111+
continue;
112+
}
102113

103114
u16 vid = SDL_GetJoystickVendor(jp.handle);
104115
u16 pid = SDL_GetJoystickProduct(jp.handle);

0 commit comments

Comments
 (0)