Skip to content

Commit afc69cc

Browse files
committed
Handle missing gamepads during button configuration
1 parent 6f78133 commit afc69cc

1 file changed

Lines changed: 26 additions & 17 deletions

File tree

platforms/shared/desktop/gui_popups.cpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -231,31 +231,40 @@ void gui_popup_modal_gamepad(int pad)
231231
{
232232
if (ImGui::BeginPopupModal("Gamepad Configuration", NULL, ImGuiWindowFlags_AlwaysAutoResize))
233233
{
234-
ImGui::Text("Press any button in your gamepad...\n\n");
234+
SDL_Gamepad* controller = gamepad_controller[pad];
235+
236+
if (IsValidPointer(controller))
237+
ImGui::Text("Press any button in your gamepad...\n\n");
238+
else
239+
ImGui::Text("No gamepad detected.\n\n");
240+
235241
ImGui::Separator();
236242

237-
for (int i = 0; i < SDL_GAMEPAD_BUTTON_COUNT; i++)
243+
if (IsValidPointer(controller))
238244
{
239-
if (SDL_GetGamepadButton(gamepad_controller[pad], (SDL_GamepadButton)i))
245+
for (int i = 0; i < SDL_GAMEPAD_BUTTON_COUNT; i++)
240246
{
241-
*gui_configured_button = i;
242-
ImGui::CloseCurrentPopup();
243-
break;
247+
if (SDL_GetGamepadButton(controller, (SDL_GamepadButton)i))
248+
{
249+
*gui_configured_button = i;
250+
ImGui::CloseCurrentPopup();
251+
break;
252+
}
244253
}
245-
}
246254

247-
for (int a = SDL_GAMEPAD_AXIS_LEFTX; a < SDL_GAMEPAD_AXIS_COUNT; a++)
248-
{
249-
if (a != SDL_GAMEPAD_AXIS_LEFT_TRIGGER && a != SDL_GAMEPAD_AXIS_RIGHT_TRIGGER)
250-
continue;
255+
for (int a = SDL_GAMEPAD_AXIS_LEFTX; a < SDL_GAMEPAD_AXIS_COUNT; a++)
256+
{
257+
if (a != SDL_GAMEPAD_AXIS_LEFT_TRIGGER && a != SDL_GAMEPAD_AXIS_RIGHT_TRIGGER)
258+
continue;
251259

252-
Sint16 value = SDL_GetGamepadAxis(gamepad_controller[pad], (SDL_GamepadAxis)a);
260+
Sint16 value = SDL_GetGamepadAxis(controller, (SDL_GamepadAxis)a);
253261

254-
if (value > GAMEPAD_VBTN_AXIS_THRESHOLD)
255-
{
256-
*gui_configured_button = GAMEPAD_VBTN_AXIS_BASE + a;
257-
ImGui::CloseCurrentPopup();
258-
break;
262+
if (value > GAMEPAD_VBTN_AXIS_THRESHOLD)
263+
{
264+
*gui_configured_button = GAMEPAD_VBTN_AXIS_BASE + a;
265+
ImGui::CloseCurrentPopup();
266+
break;
267+
}
259268
}
260269
}
261270

0 commit comments

Comments
 (0)