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");
callback(userdata, NULL, -1);
#else
if (filters) {
const char *msg = validate_filters(filters);
if (msg) {
@@ -44,6 +45,7 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback
callback(userdata, NULL, -1);
return;
}
}
if (SDL_GetHint(SDL_HINT_FILE_DIALOG_DRIVER) != NULL) {
SDL_SetError("File dialog driver unsupported");
@@ -73,6 +75,7 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback
break;
};
if (filters) {
int n = -1;
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
@@ -118,6 +121,7 @@ void show_file_dialog(cocoa_FileDialogType type, SDL_DialogFileCallback callback
[dialog setAllowedFileTypes:types];
}
}
}
/* Keep behavior consistent with other platforms */
[dialog setAllowsOtherFileTypes:YES];