Skip to content

Commit

Permalink
Properly handle controllers when not plugged in to first port
Browse files Browse the repository at this point in the history
  • Loading branch information
LoveMHz committed Dec 7, 2020
1 parent 803572f commit 43a6ec9
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ int SCREEN_HEIGHT = 480;
#define MIN(x, y) (((x) < (y)) ? (x) : (y))

SDL_Renderer *gRenderer = NULL;
// SDL_Joystick *gGameController = NULL;
SDL_GameController *gameController = NULL;

TTF_Font *gFont = NULL;
TTF_Font *gFontSmall = NULL;
Expand Down Expand Up @@ -84,11 +82,14 @@ int main(void) {
"Couldn't find any joysticks.\n");
printSDLErrorAndReboot();
} else {
if (SDL_IsGameController(0)) {
gameController = SDL_GameControllerOpen(0);
}
if (gameController == nullptr) {
printSDLErrorAndReboot();
SDL_GameController *controller = NULL;
for (int i = 0; i < SDL_NumJoysticks(); ++i) {
if (SDL_IsGameController(i)) {
controller = SDL_GameControllerOpen(i);
if (controller == nullptr) {
printSDLErrorAndReboot();
}
}
}
}

Expand Down

0 comments on commit 43a6ec9

Please sign in to comment.