diff --git a/android/app/src/main/java/com/classicube/MainActivity.java b/android/app/src/main/java/com/classicube/MainActivity.java index f4d15be46..07ed4bcd3 100644 --- a/android/app/src/main/java/com/classicube/MainActivity.java +++ b/android/app/src/main/java/com/classicube/MainActivity.java @@ -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; diff --git a/src/Logger.c b/src/Logger.c index f294cf5c0..8ac8014b0 100644 --- a/src/Logger.c +++ b/src/Logger.c @@ -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); } diff --git a/src/Platform.h b/src/Platform.h index c1cdeb85c..9146166f3 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -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) diff --git a/src/Platform_Android.c b/src/Platform_Android.c index 2f86412f1..608ba9052 100644 --- a/src/Platform_Android.c +++ b/src/Platform_Android.c @@ -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);