Skip to content

Commit 170fb29

Browse files
authored
Merge pull request #10 from RyeMutt/rye/fixsdl3
Fix SDL3 device init
2 parents bde522d + 45be5d9 commit 170fb29

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

libndofdev/ndofdev.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,24 @@ int ndof_init_first(NDOF_Device *in_out_dev, void *param)
261261

262262
} else {
263263
#ifdef USE_SDL3
264+
if(!SDL_HasJoystick())
265+
{
266+
return -1;
267+
}
268+
269+
int count = 0;
270+
SDL_JoystickID *ids = SDL_GetJoysticks(&count);
271+
if(0 >= count)
272+
{
273+
return -1;
274+
}
275+
276+
// Get ID of first device
277+
SDL_JoystickID first_device = ids[0];
278+
SDL_free(ids);
279+
264280
// SpaceNavigator not found, use SDL Joystick
265-
SDL_Joystick *j = SDL_OpenJoystick(0);
281+
SDL_Joystick *j = SDL_OpenJoystick(first_device);
266282
if(j)
267283
{
268284
in_out_dev->axes_count = SDL_GetNumJoystickAxes(j) + SDL_GetNumJoystickHats(j) * 2; // each hat has 2 axes

0 commit comments

Comments
 (0)