Furnace has stopped.

• Diagnose later
This commit is contained in:
tildearrow 2022-11-05 19:24:14 -05:00
parent e75d1ef411
commit 6a6ca22ebe
3 changed files with 60 additions and 2 deletions

View file

@ -4,6 +4,8 @@
#ifdef USE_NFD #ifdef USE_NFD
#include <nfd.h> #include <nfd.h>
#elif defined(ANDROID)
#include <SDL.h>
#else #else
#include "../../extern/pfd-fixed/portable-file-dialogs.h" #include "../../extern/pfd-fixed/portable-file-dialogs.h"
#endif #endif
@ -87,6 +89,45 @@ bool FurnaceGUIFileDialog::openLoad(String header, std::vector<String> filter, c
#else #else
dialogO=new std::thread(_nfdThread,NFDState(false,header,filter,path,clickCallback,allowMultiple),&dialogOK,&nfdResult,&hasError); dialogO=new std::thread(_nfdThread,NFDState(false,header,filter,path,clickCallback,allowMultiple),&dialogOK,&nfdResult,&hasError);
#endif #endif
#elif defined(ANDROID)
hasError=false;
if (jniEnv==NULL) {
jniEnv=(JNIEnv*)SDL_AndroidGetJNIEnv();
if (jniEnv==NULL) {
hasError=true;
logE("could not acquire JNI env!");
return false;
}
}
jobject activity=(jobject)SDL_AndroidGetActivity();
if (activity==NULL) {
hasError=true;
logE("the Activity is NULL!");
return false;
}
jclass class_=jniEnv->GetObjectClass(activity);
jmethodID showFileDialog=jniEnv->GetMethodID(class_,"showFileDialog","()B");
if (showFileDialog==NULL) {
logE("method showFileDialog not found!");
hasError=true;
jniEnv->DeleteLocalRef(class_);
jniEnv->DeleteLocalRef(activity);
return false;
}
jboolean mret=jniEnv->CallBooleanMethod(activity,showFileDialog);
if (!(bool)mret) {
hasError=true;
logW("could not open Android file picker...");
}
jniEnv->DeleteLocalRef(class_);
jniEnv->DeleteLocalRef(activity);
return true;
#else #else
dialogO=new pfd::open_file(header,path,filter,allowMultiple?(pfd::opt::multiselect):(pfd::opt::none)); dialogO=new pfd::open_file(header,path,filter,allowMultiple?(pfd::opt::multiselect):(pfd::opt::none));
hasError=!pfd::settings::available(); hasError=!pfd::settings::available();
@ -113,6 +154,8 @@ bool FurnaceGUIFileDialog::openSave(String header, std::vector<String> filter, c
#else #else
dialogS=new std::thread(_nfdThread,NFDState(true,header,filter,path,NULL,false),&dialogOK,&nfdResult,&hasError); dialogS=new std::thread(_nfdThread,NFDState(true,header,filter,path,NULL,false),&dialogOK,&nfdResult,&hasError);
#endif #endif
#elif defined(ANDROID)
hasError=true; // TODO
#else #else
dialogS=new pfd::save_file(header,path,filter); dialogS=new pfd::save_file(header,path,filter);
hasError=!pfd::settings::available(); hasError=!pfd::settings::available();
@ -141,7 +184,9 @@ void FurnaceGUIFileDialog::close() {
#ifdef USE_NFD #ifdef USE_NFD
dialogS->join(); dialogS->join();
#endif #endif
#ifndef ANDROID
delete dialogS; delete dialogS;
#endif
dialogS=NULL; dialogS=NULL;
} }
} else { } else {
@ -149,7 +194,9 @@ void FurnaceGUIFileDialog::close() {
#ifdef USE_NFD #ifdef USE_NFD
dialogO->join(); dialogO->join();
#endif #endif
#ifndef ANDROID
delete dialogO; delete dialogO;
#endif
dialogO=NULL; dialogO=NULL;
} }
} }
@ -179,6 +226,9 @@ bool FurnaceGUIFileDialog::render(const ImVec2& min, const ImVec2& max) {
return true; return true;
} }
return false; return false;
#elif defined(ANDROID)
// TODO: detect when file picker is closed
return false;
#else #else
if (saving) { if (saving) {
if (dialogS!=NULL) { if (dialogS!=NULL) {

View file

@ -15,6 +15,8 @@
#define NFD_NON_THREADED #define NFD_NON_THREADED
#endif #endif
#elif defined(ANDROID)
#include <jni.h>
#else #else
namespace pfd { namespace pfd {
class open_file; class open_file;
@ -36,6 +38,10 @@ class FurnaceGUIFileDialog {
std::thread* dialogS; std::thread* dialogS;
std::atomic<bool> dialogOK; std::atomic<bool> dialogOK;
std::vector<String> nfdResult; std::vector<String> nfdResult;
#elif defined(ANDROID)
JNIEnv* jniEnv;
void* dialogO;
void* dialogS;
#else #else
pfd::open_file* dialogO; pfd::open_file* dialogO;
pfd::save_file* dialogS; pfd::save_file* dialogS;
@ -55,6 +61,9 @@ class FurnaceGUIFileDialog {
opened(false), opened(false),
saving(false), saving(false),
hasError(false), hasError(false),
#ifdef ANDROID
jniEnv(NULL),
#endif
dialogO(NULL), dialogO(NULL),
dialogS(NULL) {} dialogS(NULL) {}
}; };

View file

@ -40,9 +40,8 @@
#define POWER_SAVE_DEFAULT 0 #define POWER_SAVE_DEFAULT 0
#endif #endif
#if defined(__HAIKU__) || defined(IS_MOBILE) #if defined(__HAIKU__)
// NFD doesn't support Haiku // NFD doesn't support Haiku
// I still haven't implemented Android file picker
#define SYS_FILE_DIALOG_DEFAULT 0 #define SYS_FILE_DIALOG_DEFAULT 0
#else #else
#define SYS_FILE_DIALOG_DEFAULT 1 #define SYS_FILE_DIALOG_DEFAULT 1