[Scummvm-git-logs] scummvm master -> 107ad485757f47df7a63457ecca55e2aa8d62777

bluegr noreply at scummvm.org
Sat Oct 25 23:34:40 UTC 2025


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
107ad48575 SDL: Fix joystick initialization


Commit: 107ad485757f47df7a63457ecca55e2aa8d62777
    https://github.com/scummvm/scummvm/commit/107ad485757f47df7a63457ecca55e2aa8d62777
Author: Ingo van Lil (inguin at gmx.de)
Date: 2025-10-26T02:34:36+03:00

Commit Message:
SDL: Fix joystick initialization

The SDL_GetJoysticks() function returns an array of connected joystick
IDs that need to be used with SDL_OpenJoystick() and related functions.

The array also needs to be freed when it is no longer needed.

Changed paths:
    backends/events/sdl/sdl3-events.cpp


diff --git a/backends/events/sdl/sdl3-events.cpp b/backends/events/sdl/sdl3-events.cpp
index 8fbca068593..3cf4c346936 100644
--- a/backends/events/sdl/sdl3-events.cpp
+++ b/backends/events/sdl/sdl3-events.cpp
@@ -884,18 +884,22 @@ bool SdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) {
 
 void SdlEventSource::openJoystick(int joystickIndex) {
 	int numJoysticks = 0;
-	SDL_GetJoysticks(&numJoysticks);
-	if (numJoysticks > joystickIndex) {
-		if (SDL_IsGamepad(joystickIndex)) {
-			_controller = SDL_OpenGamepad(joystickIndex);
+	auto joystickIds = SDL_GetJoysticks(&numJoysticks);
+	if (!joystickIds) {
+		warning("Failed to get connected joysticks: %s", SDL_GetError());
+	} else if (numJoysticks > joystickIndex) {
+		auto joystickId = joystickIds[joystickIndex];
+		if (SDL_IsGamepad(joystickId)) {
+			_controller = SDL_OpenGamepad(joystickId);
 			debug("Using game controller: %s", SDL_GetGamepadName(_controller));
 		} else {
-			_joystick = SDL_OpenJoystick(joystickIndex);
+			_joystick = SDL_OpenJoystick(joystickId);
 			debug("Using joystick: %s", SDL_GetJoystickName(_joystick));
 		}
 	} else {
 		debug(5, "Invalid joystick: %d", joystickIndex);
 	}
+	SDL_free(joystickIds);
 }
 
 void SdlEventSource::closeJoystick() {




More information about the Scummvm-git-logs mailing list