testcontroller: Don't query the mapping list until after they are available.

The included ones need to wait until SDL_Init has run, or you'll get an empty
list, and we might also be adding more from an external gamecontrollerdb.txt
file, too.
main
Ryan C. Gordon 2023-11-29 10:33:31 -05:00
parent df05d5eff4
commit c5daf8adb1
1 changed files with 15 additions and 10 deletions

View File

@ -1876,6 +1876,7 @@ int main(int argc, char *argv[])
int screen_width, screen_height;
SDL_Rect area;
int gamepad_index = -1;
SDL_bool show_mappings = SDL_FALSE;
SDLTest_CommonState *state;
/* Initialize test framework */
@ -1902,16 +1903,7 @@ int main(int argc, char *argv[])
consumed = SDLTest_CommonArg(state, i);
if (!consumed) {
if (SDL_strcmp(argv[i], "--mappings") == 0) {
int map_i;
SDL_Log("Supported mappings:\n");
for (map_i = 0; map_i < SDL_GetNumGamepadMappings(); ++map_i) {
char *mapping = SDL_GetGamepadMappingForIndex(map_i);
if (mapping) {
SDL_Log("\t%s\n", mapping);
SDL_free(mapping);
}
}
SDL_Log("\n");
show_mappings = SDL_TRUE;
consumed = 1;
} else if (SDL_strcmp(argv[i], "--virtual") == 0) {
OpenVirtualGamepad();
@ -1944,6 +1936,19 @@ int main(int argc, char *argv[])
SDL_AddGamepadMappingsFromFile("gamecontrollerdb.txt");
if (show_mappings) {
int map_i;
SDL_Log("Supported mappings:\n");
for (map_i = 0; map_i < SDL_GetNumGamepadMappings(); ++map_i) {
char *mapping = SDL_GetGamepadMappingForIndex(map_i);
if (mapping) {
SDL_Log("\t%s\n", mapping);
SDL_free(mapping);
}
}
SDL_Log("\n");
}
/* Create a window to display gamepad state */
content_scale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay());
if (content_scale == 0.0f) {