android: better clean-up on exit

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1290 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
beuc 2012-05-03 13:32:06 +00:00
parent d7eef58fb4
commit d807511ff9
2 changed files with 13 additions and 2 deletions

View File

@ -133,6 +133,7 @@ static unsigned char key_ascii(struct android_app* app, AInputEvent* event) {
int ascii = (*env)->CallIntMethod(env, keyEvent, KeyEvent_getUnicodeChar, AKeyEvent_getMetaState(event)); int ascii = (*env)->CallIntMethod(env, keyEvent, KeyEvent_getUnicodeChar, AKeyEvent_getMetaState(event));
/* LOGI("getUnicodeChar(%d) = %d ('%c')", AKeyEvent_getKeyCode(event), ascii, ascii); */ /* LOGI("getUnicodeChar(%d) = %d ('%c')", AKeyEvent_getKeyCode(event), ascii, ascii); */
(*vm)->DetachCurrentThread(vm);
return ascii; return ascii;
} }
@ -319,8 +320,8 @@ void handle_cmd(struct android_app* app, int32_t cmd) {
fgDestroyWindow(fgDisplay.pDisplay.single_window); fgDestroyWindow(fgDisplay.pDisplay.single_window);
break; break;
case APP_CMD_DESTROY: case APP_CMD_DESTROY:
/* Not reached because GLUT exit()s when last window is closed */
LOGI("handle_cmd: APP_CMD_DESTROY"); LOGI("handle_cmd: APP_CMD_DESTROY");
/* glue has already set android_app->destroyRequested=1 */
break; break;
case APP_CMD_GAINED_FOCUS: case APP_CMD_GAINED_FOCUS:
LOGI("handle_cmd: APP_CMD_GAINED_FOCUS"); LOGI("handle_cmd: APP_CMD_GAINED_FOCUS");
@ -393,7 +394,7 @@ void fgPlatformProcessSingleEvent ( void )
void fgPlatformMainLoopPreliminaryWork ( void ) void fgPlatformMainLoopPreliminaryWork ( void )
{ {
printf("fgPlatformMainLoopPreliminaryWork\n"); LOGI("fgPlatformMainLoopPreliminaryWork\n");
key_init(); key_init();

View File

@ -127,6 +127,8 @@ static void extract_assets(struct android_app* app) {
AAssetDir_close(assetDir); AAssetDir_close(assetDir);
} }
} }
(*vm)->DetachCurrentThread(vm);
} }
/** /**
@ -155,5 +157,13 @@ void android_main(struct android_app* app) {
} }
LOGI("android_main: end"); LOGI("android_main: end");
/* Finish processing all events (namely APP_CMD_DESTROY) before
exiting thread */
while (!app->destroyRequested)
fgPlatformProcessSingleEvent();
/* In theory we should let NativeActivity restart us, however this
doesn't work well yet, so force exit */
exit(0); exit(0);
} }