Skip to content

Commit 92b90a1

Browse files
authored
Merge pull request #1545 from DickSmith/release
fix: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR) crashes
2 parents a007089 + fc576c1 commit 92b90a1

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

test-app/runtime/src/main/cpp/Runtime.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,23 @@ using namespace tns;
4343
bool tns::LogEnabled = true;
4444
SimpleAllocator g_allocator;
4545

46-
void SIGABRT_handler(int sigNumber) {
47-
throw NativeScriptException("JNI Exception occurred (SIGABRT).\n=======\nCheck the 'adb logcat' for additional information about the error.\n=======\n");
46+
void SIG_handler(int sigNumber) {
47+
stringstream msg;
48+
msg << "JNI Exception occurred (";
49+
switch (sigNumber) {
50+
case SIGABRT:
51+
msg << "SIGABRT";
52+
break;
53+
case SIGSEGV:
54+
msg << "SIGSEGV";
55+
break;
56+
default:
57+
// Shouldn't happen, but for completeness
58+
msg << "Signal #" << sigNumber;
59+
break;
60+
}
61+
msg << ").\n=======\nCheck the 'adb logcat' for additional information about the error.\n=======\n";
62+
throw NativeScriptException(msg.str());
4863
}
4964

5065
void Runtime::Init(JavaVM* vm, void* reserved) {
@@ -56,11 +71,12 @@ void Runtime::Init(JavaVM* vm, void* reserved) {
5671
JEnv::Init(s_jvm);
5772
}
5873

59-
if (m_androidVersion > 25) {
60-
// handle SIGABRT only on API level > 25 as the handling is not so efficient in older versions
74+
// handle SIGABRT/SIGSEGV only on API level > 20 as the handling is not so efficient in older versions
75+
if (m_androidVersion > 20) {
6176
struct sigaction action;
62-
action.sa_handler = SIGABRT_handler;
77+
action.sa_handler = SIG_handler;
6378
sigaction(SIGABRT, &action, NULL);
79+
sigaction(SIGSEGV, &action, NULL);
6480
}
6581
}
6682

0 commit comments

Comments
 (0)