first of all, format your code.
yeah, your code is very wrong. let’s forget your current approach and work from zero.
a callback is a function. you define a function obeying this signature: SDL3/SDL_DialogFileCallback - SDL Wiki
e.g.:
void my_dialog_callback(void *userdata, char const *const *filelist, int filter)
{
(void)userdata;
(void)filter;
if (NULL == filelist)
SDL_Log("Dialog error: %s\n", SDL_GetError());
else if (NULL == *filelist)
SDL_Log("No file selected\n");
else for (; *filelist != NULL; filelist++)
SDL_Log("I got file %s\n", *filelist);
}
then somewhere in your program initialization (your main function), just call:
SDL_ShowOpenFileDialog(my_dialog_callback, NULL, NULL, NULL, 0, NULL, true);
I don’t what is this std::async()
you used, but it is probably wrong. just because the documentation says “This is an asynchronous function” you can’t go around calling code just because the keyword “async” is associated with it. be careful and be 100% sure of everything you are doing. never ever guess. “async” is among the misunderstood and misused words, to make matters worse, so be extra extra careful.
notice in documentation for SDL_ShowOpenFileDialog
: “This function should be called only from the main thread”, so yeah, just call it from main thread.
finally, you callback code needs to be thread-safe. what do you want to do with the files selected? depending on your use case, atomics can solve it trivially, otherwise you will have to look into synchronization primitives such as a mutex.
p.s.: I’m a C programmer, so I just use a function as callback. maybe C++ geniuses can write a lambda thing or a closure or whatever as a callback, I don’t know.