mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 09:01:57 -05:00
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:
parent
3d7054f90d
commit
5898f4edef
4 changed files with 44 additions and 20 deletions
|
@ -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
|
||||
|
||||
// implements InputQueue.Callback
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
// ======================================
|
||||
// -------------- COMMANDS --------------
|
||||
// ======================================
|
||||
public class MainActivity extends Activity
|
||||
{
|
||||
// ==================================================================
|
||||
// ---------------------------- COMMANDS ----------------------------
|
||||
// ==================================================================
|
||||
// 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
|
||||
// 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_LOW_MEMORY = 18;
|
||||
|
||||
// ======================================
|
||||
// --------------- EVENTS ---------------
|
||||
// ======================================
|
||||
|
||||
// ====================================================================
|
||||
// ------------------------------ EVENTS ------------------------------
|
||||
// ====================================================================
|
||||
InputMethodManager input;
|
||||
// static to persist across activity destroy/create
|
||||
static boolean gameRunning;
|
||||
|
@ -386,9 +387,10 @@ public class MainActivity extends Activity {
|
|||
native void runGameAsync();
|
||||
native void updateInstance();
|
||||
|
||||
// ======================================
|
||||
// --------------- VIEWS ----------------
|
||||
// ======================================
|
||||
|
||||
// ====================================================================
|
||||
// ------------------------------ VIEWS -------------------------------
|
||||
// ====================================================================
|
||||
volatile boolean fullscreen;
|
||||
// static to persist across activity destroy/create
|
||||
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)
|
||||
public void setupForGame() {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ======================================
|
||||
// --------------- WINDOW ---------------
|
||||
// ======================================
|
||||
// ====================================================================
|
||||
// ------------------------------ WINDOW ------------------------------
|
||||
// ====================================================================
|
||||
// Implements java Android side of the Android Window backend (See Window.c)
|
||||
volatile int keyboardType;
|
||||
volatile String keyboardText = "";
|
||||
|
@ -791,9 +795,10 @@ public class MainActivity extends Activity {
|
|||
return "";
|
||||
}
|
||||
|
||||
// ======================================
|
||||
// ---------------- HTTP ----------------
|
||||
// ======================================
|
||||
|
||||
// ======================================================================
|
||||
// -------------------------------- HTTP --------------------------------
|
||||
// ======================================================================
|
||||
// Implements java Android side of the Android HTTP backend (See Http.c)
|
||||
static HttpURLConnection conn;
|
||||
static InputStream src;
|
||||
|
|
|
@ -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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -247,6 +247,7 @@ void Platform_ShareScreenshot(const cc_string* filename);
|
|||
extern jclass App_Class;
|
||||
extern jobject App_Instance;
|
||||
extern JavaVM* VM_Ptr;
|
||||
void Platform_TryLogJavaError(void);
|
||||
|
||||
#define JavaGetCurrentEnv(env) (*VM_Ptr)->AttachCurrentThread(VM_Ptr, &env, NULL)
|
||||
#define JavaMakeConst(env, str) (*env)->NewStringUTF(env, str)
|
||||
|
|
|
@ -63,6 +63,20 @@ cc_result Updater_SetNewBuildTime(cc_uint64 t) { return ERR_NOT_SUPPORTED; }
|
|||
/*########################################################################################################################*
|
||||
*--------------------------------------------------------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) {
|
||||
cc_string path; char pathBuffer[FILENAME_SIZE];
|
||||
String_InitArray(path, pathBuffer);
|
||||
|
|
Loading…
Reference in a new issue