Android: Try to show crash dialog for Java unhandled exceptions

Doesn't seem to work for UI thread and the crash dialog contents is pretty much useless anyways, but at least it's something
This commit is contained in:
UnknownShadow200 2021-09-30 23:07:55 +10:00
parent 3d7054f90d
commit 5898f4edef
4 changed files with 44 additions and 20 deletions

View file

@ -54,11 +54,11 @@ import android.view.inputmethod.InputMethodManager;
// was added in, as this will make things easier if the minimum required API level is ever changed again // was added in, as this will make things easier if the minimum required API level is ever changed again
// implements InputQueue.Callback // implements InputQueue.Callback
public class MainActivity extends Activity { public class MainActivity extends Activity
{
// ====================================== // ==================================================================
// -------------- COMMANDS -------------- // ---------------------------- COMMANDS ----------------------------
// ====================================== // ==================================================================
// The main thread (which receives events) is separate from the game thread (which processes events) // The main thread (which receives events) is separate from the game thread (which processes events)
// Therefore pushing/pulling events must be thread-safe, which is achieved through ConcurrentLinkedQueue // Therefore pushing/pulling events must be thread-safe, which is achieved through ConcurrentLinkedQueue
// Additionally, a cache is used (freeCmds) to avoid constantly allocating NativeCmdArgs instances // Additionally, a cache is used (freeCmds) to avoid constantly allocating NativeCmdArgs instances
@ -134,9 +134,10 @@ public class MainActivity extends Activity {
final static int CMD_CONFIG_CHANGED = 17; final static int CMD_CONFIG_CHANGED = 17;
final static int CMD_LOW_MEMORY = 18; final static int CMD_LOW_MEMORY = 18;
// ======================================
// --------------- EVENTS --------------- // ====================================================================
// ====================================== // ------------------------------ EVENTS ------------------------------
// ====================================================================
InputMethodManager input; InputMethodManager input;
// static to persist across activity destroy/create // static to persist across activity destroy/create
static boolean gameRunning; static boolean gameRunning;
@ -386,9 +387,10 @@ public class MainActivity extends Activity {
native void runGameAsync(); native void runGameAsync();
native void updateInstance(); native void updateInstance();
// ======================================
// --------------- VIEWS ---------------- // ====================================================================
// ====================================== // ------------------------------ VIEWS -------------------------------
// ====================================================================
volatile boolean fullscreen; volatile boolean fullscreen;
// static to persist across activity destroy/create // static to persist across activity destroy/create
static final Semaphore winDestroyedSem = new Semaphore(0, true); static final Semaphore winDestroyedSem = new Semaphore(0, true);
@ -560,9 +562,10 @@ public class MainActivity extends Activity {
} }
} }
// ======================================
// -------------- PLATFORM -------------- // ==================================================================
// ====================================== // ---------------------------- PLATFORM ----------------------------
// ==================================================================
// Implements java Android side of the Android Platform backend (See Platform.c) // Implements java Android side of the Android Platform backend (See Platform.c)
public void setupForGame() { public void setupForGame() {
// Once a surface has been locked for drawing with canvas, can't ever be detached // Once a surface has been locked for drawing with canvas, can't ever be detached
@ -607,10 +610,11 @@ public class MainActivity extends Activity {
return 0; return 0;
} }
} }
// ====================================== // ====================================================================
// --------------- WINDOW --------------- // ------------------------------ WINDOW ------------------------------
// ====================================== // ====================================================================
// Implements java Android side of the Android Window backend (See Window.c) // Implements java Android side of the Android Window backend (See Window.c)
volatile int keyboardType; volatile int keyboardType;
volatile String keyboardText = ""; volatile String keyboardText = "";
@ -791,9 +795,10 @@ public class MainActivity extends Activity {
return ""; return "";
} }
// ======================================
// ---------------- HTTP ---------------- // ======================================================================
// ====================================== // -------------------------------- HTTP --------------------------------
// ======================================================================
// Implements java Android side of the Android HTTP backend (See Http.c) // Implements java Android side of the Android HTTP backend (See Http.c)
static HttpURLConnection conn; static HttpURLConnection conn;
static InputStream src; static InputStream src;

View file

@ -818,6 +818,10 @@ static void SignalHandler(int sig, siginfo_t* info, void* ctx) {
String_Format3(&msg, "Unhandled signal %i (code %i) at 0x%x", &type, &code, &addr); String_Format3(&msg, "Unhandled signal %i (code %i) at 0x%x", &type, &code, &addr);
msg.buffer[msg.length] = '\0'; msg.buffer[msg.length] = '\0';
#if defined CC_BUILD_ANDROID
/* deliberate Dalvik VM abort, try to log a nicer error for this */
if (type == SIGSEGV && addr == 0xDEADD00D) Platform_TryLogJavaError();
#endif
AbortCommon(0, msg.buffer, ctx); AbortCommon(0, msg.buffer, ctx);
} }

View file

@ -247,6 +247,7 @@ void Platform_ShareScreenshot(const cc_string* filename);
extern jclass App_Class; extern jclass App_Class;
extern jobject App_Instance; extern jobject App_Instance;
extern JavaVM* VM_Ptr; extern JavaVM* VM_Ptr;
void Platform_TryLogJavaError(void);
#define JavaGetCurrentEnv(env) (*VM_Ptr)->AttachCurrentThread(VM_Ptr, &env, NULL) #define JavaGetCurrentEnv(env) (*VM_Ptr)->AttachCurrentThread(VM_Ptr, &env, NULL)
#define JavaMakeConst(env, str) (*env)->NewStringUTF(env, str) #define JavaMakeConst(env, str) (*env)->NewStringUTF(env, str)

View file

@ -63,6 +63,20 @@ cc_result Updater_SetNewBuildTime(cc_uint64 t) { return ERR_NOT_SUPPORTED; }
/*########################################################################################################################* /*########################################################################################################################*
*--------------------------------------------------------Platform---------------------------------------------------------* *--------------------------------------------------------Platform---------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
void Platform_TryLogJavaError(void) {
JNIEnv* env;
jthrowable err;
JavaGetCurrentEnv(env);
err = (*env)->ExceptionOccurred(env);
if (!err) return;
Platform_LogConst("PANIC");
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
/* TODO actually do something */
}
void Platform_ShareScreenshot(const cc_string* filename) { void Platform_ShareScreenshot(const cc_string* filename) {
cc_string path; char pathBuffer[FILENAME_SIZE]; cc_string path; char pathBuffer[FILENAME_SIZE];
String_InitArray(path, pathBuffer); String_InitArray(path, pathBuffer);