Skip to content

Commit

Permalink
Fixed access of command line arguments on Android in two test programs.
Browse files Browse the repository at this point in the history
  • Loading branch information
philippwiesemann committed Dec 24, 2013
1 parent 36cbd50 commit 65f0142
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions test/controllermap.c
Expand Up @@ -386,15 +386,18 @@ main(int argc, char *argv[])
SDL_bool reportederror = SDL_FALSE;
SDL_bool keepGoing = SDL_TRUE;
SDL_Event event;
int device;
#ifdef ANDROID
joystick = SDL_JoystickOpen(0);
device = 0;
#else
joystick = SDL_JoystickOpen(atoi(argv[1]));
device = atoi(argv[1]);
#endif
joystick = SDL_JoystickOpen(device);

while ( keepGoing ) {
if (joystick == NULL) {
if ( !reportederror ) {
SDL_Log("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError());
SDL_Log("Couldn't open joystick %d: %s\n", device, SDL_GetError());
keepGoing = SDL_FALSE;
reportederror = SDL_TRUE;
}
Expand All @@ -414,7 +417,7 @@ main(int argc, char *argv[])
|| (event.type == SDL_MOUSEBUTTONDOWN)) {
keepGoing = SDL_FALSE;
} else if (event.type == SDL_JOYDEVICEADDED) {
joystick = SDL_JoystickOpen(atoi(argv[1]));
joystick = SDL_JoystickOpen(device);
break;
}
}
Expand Down
11 changes: 7 additions & 4 deletions test/testjoystick.c
Expand Up @@ -251,15 +251,18 @@ main(int argc, char *argv[])
SDL_bool reportederror = SDL_FALSE;
SDL_bool keepGoing = SDL_TRUE;
SDL_Event event;
int device;
#ifdef ANDROID
joystick = SDL_JoystickOpen(0);
device = 0;
#else
joystick = SDL_JoystickOpen(atoi(argv[1]));
device = atoi(argv[1]);
#endif
joystick = SDL_JoystickOpen(device);

while ( keepGoing ) {
if (joystick == NULL) {
if ( !reportederror ) {
SDL_Log("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError());
SDL_Log("Couldn't open joystick %d: %s\n", device, SDL_GetError());
keepGoing = SDL_FALSE;
reportederror = SDL_TRUE;
}
Expand All @@ -279,7 +282,7 @@ main(int argc, char *argv[])
|| (event.type == SDL_MOUSEBUTTONDOWN)) {
keepGoing = SDL_FALSE;
} else if (event.type == SDL_JOYDEVICEADDED) {
joystick = SDL_JoystickOpen(atoi(argv[1]));
joystick = SDL_JoystickOpen(device);
break;
}
}
Expand Down

0 comments on commit 65f0142

Please sign in to comment.