Fix improper handling of NULL dialog filter on Cocoa

This commit is contained in:
Semphris
2024-05-02 12:22:23 -04:00
committed by Sam Lantinga
parent 9f842e9b5a
commit 4ac8968f65

View File

@@ -37,6 +37,7 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback
SDL_SetError("tvOS and iOS don't support path-based file dialogs"); SDL_SetError("tvOS and iOS don't support path-based file dialogs");
callback(userdata, NULL, -1); callback(userdata, NULL, -1);
#else #else
if (filters) {
const char *msg = validate_filters(filters); const char *msg = validate_filters(filters);
if (msg) { if (msg) {
@@ -44,6 +45,7 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback
callback(userdata, NULL, -1); callback(userdata, NULL, -1);
return; return;
} }
}
if (SDL_GetHint(SDL_HINT_FILE_DIALOG_DRIVER) != NULL) { if (SDL_GetHint(SDL_HINT_FILE_DIALOG_DRIVER) != NULL) {
SDL_SetError("File dialog driver unsupported"); SDL_SetError("File dialog driver unsupported");
@@ -73,6 +75,7 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback
break; break;
}; };
if (filters) {
int n = -1; int n = -1;
while (filters[++n].name && filters[n].pattern); while (filters[++n].name && filters[n].pattern);
// On macOS 11.0 and up, this is an array of UTType. Prior to that, it's an array of NSString // On macOS 11.0 and up, this is an array of UTType. Prior to that, it's an array of NSString
@@ -118,6 +121,7 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback
[dialog setAllowedFileTypes:types]; [dialog setAllowedFileTypes:types];
} }
} }
}
/* Keep behavior consistent with other platforms */ /* Keep behavior consistent with other platforms */
[dialog setAllowsOtherFileTypes:YES]; [dialog setAllowsOtherFileTypes:YES];