GUI: fix macOS system file picker crash

This commit is contained in:
tildearrow 2022-06-19 18:51:51 -05:00
parent d47c50edaf
commit 35bc757adf
4 changed files with 20 additions and 0 deletions

View File

@ -18,6 +18,8 @@ static NSArray *BuildAllowedFileTypes( const char *filterList )
{
// Commas and semicolons are the same thing on this platform
// like what about THIS INSTEAD!
// NSMutableArray *buildFilterList = NSMutableArray::alloc()->init();
NSMutableArray *buildFilterList = [[NSMutableArray alloc] init];
char typebuf[NFD_MAX_STRLEN] = {0};
@ -32,6 +34,9 @@ static NSArray *BuildAllowedFileTypes( const char *filterList )
++p_typebuf;
*p_typebuf = '\0';
// or this: NSString::stringWithUTF8String(typebuf);
// buildFilterList->addObject(thisType);
// really? did you have to make this mess?!
NSString *thisType = [NSString stringWithUTF8String: typebuf];
[buildFilterList addObject:thisType];
p_typebuf = typebuf;

View File

@ -67,7 +67,11 @@ bool FurnaceGUIFileDialog::openLoad(String header, std::vector<String> filter, c
if (sysDialog) {
#ifdef USE_NFD
dialogOK=false;
#ifdef NFD_NON_THREADED
_nfdThread(NFDState(false,header,filter,path,clickCallback),&dialogOK,&nfdResult);
#else
dialogO=new std::thread(_nfdThread,NFDState(false,header,filter,path,clickCallback),&dialogOK,&nfdResult);
#endif
#else
dialogO=new pfd::open_file(header,path,filter);
#endif
@ -87,7 +91,11 @@ bool FurnaceGUIFileDialog::openSave(String header, std::vector<String> filter, c
if (sysDialog) {
#ifdef USE_NFD
dialogOK=false;
#ifdef NFD_NON_THREADED
_nfdThread(NFDState(true,header,filter,path,NULL),&dialogOK,&nfdResult);
#else
dialogS=new std::thread(_nfdThread,NFDState(true,header,filter,path,NULL),&dialogOK,&nfdResult);
#endif
#else
dialogS=new pfd::save_file(header,path,filter);
#endif

View File

@ -10,6 +10,11 @@
#ifdef USE_NFD
#include <atomic>
#include <thread>
#ifdef __APPLE__
#define NFD_NON_THREADED
#endif
#else
namespace pfd {
class open_file;

View File

@ -3138,6 +3138,7 @@ bool FurnaceGUI::loop() {
#endif
}
#ifndef NFD_NON_THREADED
if (fileDialog->isOpen() && settings.sysFileDialog) {
ImGui::OpenPopup("System File Dialog Pending");
}
@ -3150,6 +3151,7 @@ bool FurnaceGUI::loop() {
dl->AddRectFilled(ImVec2(0.0f,0.0f),ImVec2(scrW*dpiScale,scrH*dpiScale),ImGui::ColorConvertFloat4ToU32(uiColors[GUI_COLOR_MODAL_BACKDROP]));
ImGui::EndPopup();
}
#endif
if (fileDialog->render(ImVec2(600.0f*dpiScale,400.0f*dpiScale),ImVec2(scrW*dpiScale,scrH*dpiScale))) {
bool openOpen=false;