Skip to content

Commit 659922f

Browse files
ShadowNinjakwolekr
authored andcommittedOct 15, 2015
Remove explicit syslog printing for uncaught exceptions on Android
All log operations are now added to the syslog implicitly. Also, pass along mutable string to argument vector for main().
1 parent 6f2d785 commit 659922f

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed
 

Diff for: ‎src/porting_android.cpp

+17-18
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121
#error This file may only be compiled for android!
2222
#endif
2323

24+
#include "util/numeric.h"
2425
#include "porting.h"
2526
#include "porting_android.h"
2627
#include "threading/thread.h"
2728
#include "config.h"
2829
#include "filesys.h"
2930
#include "log.h"
31+
3032
#include <sstream>
33+
#include <exception>
34+
#include <stdlib.h>
3135

3236
#ifdef GPROF
3337
#include "prof.h"
@@ -40,28 +44,23 @@ void android_main(android_app *app)
4044
int retval = 0;
4145
porting::app_global = app;
4246

43-
Thread::setName("MainThread");
47+
Thread::setName("Main");
4448

4549
try {
4650
app_dummy();
47-
char *argv[] = {(char*) "minetest"};
48-
main(sizeof(argv) / sizeof(argv[0]), argv);
49-
} catch (BaseException &e) {
50-
std::stringstream msg;
51-
msg << "Exception handled by main: " << e.what();
52-
const char *message = msg.str().c_str();
53-
__android_log_print(ANDROID_LOG_ERROR, PROJECT_NAME, "%s", message);
54-
errorstream << msg << std::endl;
51+
char *argv[] = {strdup(PROJECT_NAME), NULL};
52+
main(ARRLEN(argv) - 1, argv);
53+
free(argv[0]);
54+
} catch (std::exception &e) {
55+
errorstream << "Uncaught exception in main thread: " << e.what() << std::endl;
5556
retval = -1;
5657
} catch (...) {
57-
__android_log_print(ANDROID_LOG_ERROR, PROJECT_NAME,
58-
"An unknown exception occured!");
5958
errorstream << "Uncaught exception in main thread!" << std::endl;
6059
retval = -1;
6160
}
6261

6362
porting::cleanupAndroid();
64-
errorstream << "Shutting down." << std::endl;
63+
infostream << "Shutting down." << std::endl;
6564
exit(retval);
6665
}
6766

@@ -125,7 +124,7 @@ void initAndroid()
125124
JavaVM *jvm = app_global->activity->vm;
126125
JavaVMAttachArgs lJavaVMAttachArgs;
127126
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
128-
lJavaVMAttachArgs.name = "MinetestNativeThread";
127+
lJavaVMAttachArgs.name = PROJECT_NAME_C "NativeThread";
129128
lJavaVMAttachArgs.group = NULL;
130129
#ifdef NDEBUG
131130
// This is a ugly hack as arm v7a non debuggable builds crash without this
@@ -146,7 +145,7 @@ void initAndroid()
146145

147146
#ifdef GPROF
148147
/* in the start-up code */
149-
__android_log_print(ANDROID_LOG_ERROR, PROJECT_NAME,
148+
__android_log_print(ANDROID_LOG_ERROR, PROJECT_NAME_C,
150149
"Initializing GPROF profiler");
151150
monstartup("libminetest.so");
152151
#endif
@@ -186,8 +185,8 @@ void setExternalStorageDir(JNIEnv* lJNIEnv)
186185
lJNIEnv->ReleaseStringUTFChars(StringPath, externalPath);
187186

188187
path_storage = userPath;
189-
path_user = userPath + DIR_DELIM + PROJECT_NAME;
190-
path_share = userPath + DIR_DELIM + PROJECT_NAME;
188+
path_user = userPath + DIR_DELIM + PROJECT_NAME_C;
189+
path_share = userPath + DIR_DELIM + PROJECT_NAME_C;
191190
}
192191

193192
void showInputDialog(const std::string& acceptButton, const std::string& hint,
@@ -240,7 +239,7 @@ std::string getInputDialogValue()
240239
return text;
241240
}
242241

243-
#if not defined(SERVER)
242+
#ifndef SERVER
244243
float getDisplayDensity()
245244
{
246245
static bool firstrun = true;
@@ -290,5 +289,5 @@ v2u32 getDisplaySize()
290289
}
291290
return retval;
292291
}
293-
#endif //SERVER
292+
#endif // ndef SERVER
294293
}

0 commit comments

Comments
 (0)
Please sign in to comment.