Fixed access of command line arguments on Android in two test programs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
diff --git a/test/controllermap.c b/test/controllermap.c
index 08b85a7..df4c892 100644
--- a/test/controllermap.c
+++ b/test/controllermap.c
@@ -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;
}
@@ -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;
}
}
diff --git a/test/testjoystick.c b/test/testjoystick.c
index 9c47719..2984145 100644
--- a/test/testjoystick.c
+++ b/test/testjoystick.c
@@ -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;
}
@@ -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;
}
}