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 // 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]; NSMutableArray *buildFilterList = [[NSMutableArray alloc] init];
char typebuf[NFD_MAX_STRLEN] = {0}; char typebuf[NFD_MAX_STRLEN] = {0};
@ -32,6 +34,9 @@ static NSArray *BuildAllowedFileTypes( const char *filterList )
++p_typebuf; ++p_typebuf;
*p_typebuf = '\0'; *p_typebuf = '\0';
// or this: NSString::stringWithUTF8String(typebuf);
// buildFilterList->addObject(thisType);
// really? did you have to make this mess?!
NSString *thisType = [NSString stringWithUTF8String: typebuf]; NSString *thisType = [NSString stringWithUTF8String: typebuf];
[buildFilterList addObject:thisType]; [buildFilterList addObject:thisType];
p_typebuf = typebuf; p_typebuf = typebuf;

View file

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

View file

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

View file

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