Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gamepad fixes and error handling #505

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/FNAPlatform/SDL3_FNAPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static string ProgramInit(LaunchParameters args)
(uint) SDL.SDL_EventType.SDL_EVENT_GAMEPAD_ADDED,
(uint) SDL.SDL_EventType.SDL_EVENT_GAMEPAD_ADDED
) == 1) {
INTERNAL_AddInstance(evt[0].cdevice.which);
INTERNAL_AddInstance(evt[0].gdevice.which);
}

if (OSVersion.Equals("Windows"))
Expand Down Expand Up @@ -1094,11 +1094,11 @@ ref bool textInputSuppress
// Controller device management
else if (evt.type == (uint) SDL.SDL_EventType.SDL_EVENT_GAMEPAD_ADDED)
{
INTERNAL_AddInstance(evt.cdevice.which);
INTERNAL_AddInstance(evt.gdevice.which);
}
else if (evt.type == (uint) SDL.SDL_EventType.SDL_EVENT_GAMEPAD_REMOVED)
{
INTERNAL_RemoveInstance(evt.cdevice.which);
INTERNAL_RemoveInstance(evt.gdevice.which);
}

// Text Input
Expand Down Expand Up @@ -2017,9 +2017,19 @@ private static void INTERNAL_AddInstance(uint dev)

// Open the device!
INTERNAL_devices[which] = SDL.SDL_OpenGamepad(dev);
string error = SDL.SDL_GetError();
if (!string.IsNullOrEmpty(error)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the other checks we should use tue return value of the function instead of the error buffer

FNALoggerEXT.LogWarn("Failed to OpenGamepad: " + error);
return;
}

// We use this when dealing with GUID initialization.
IntPtr thisJoystick = SDL.SDL_GetGamepadJoystick(INTERNAL_devices[which]);
error = SDL.SDL_GetError();
if (!string.IsNullOrEmpty(error)) {
FNALoggerEXT.LogWarn("Failed to GetGamepadJoystick: " + error);
return;
}

// Pair up the instance ID to the player index.
// FIXME: Remove check after 2.0.4? -flibit
Expand Down Expand Up @@ -2093,6 +2103,12 @@ private static void INTERNAL_AddInstance(uint dev)
caps.HasAccelerometerEXT = SDL.SDL_GamepadHasSensor(INTERNAL_devices[which], SDL.SDL_SensorType.SDL_SENSOR_ACCEL);
INTERNAL_capabilities[which] = caps;

error = SDL.SDL_GetError();
if (!string.IsNullOrEmpty(error)) {
FNALoggerEXT.LogWarn("Error(s) while building gamepad caps: " + error);
return;
}

/* Store the GUID string for this device
* FIXME: Replace GetGUIDEXT string with 3 short values -flibit
*/
Expand Down Expand Up @@ -2135,6 +2151,11 @@ private static void INTERNAL_AddInstance(uint dev)
// Print controller information to stdout.
string deviceInfo;
string mapping = SDL.SDL_GetGamepadMapping(INTERNAL_devices[which]);
error = SDL.SDL_GetError();
if (!string.IsNullOrEmpty(error)) {
FNALoggerEXT.LogWarn("Failed to GetGamepadMapping: " + error);
return;
}
if (string.IsNullOrEmpty(mapping))
{
deviceInfo = "Mapping not found";
Expand Down
Loading