From 640d811809229345bc55251a23933f77111e9d8a Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 19 Jul 2011 16:01:22 +0800 Subject: [PATCH 1/3] [android] fixed #618: invoke java code(System.exit()) to finish programe --- .../src/org/cocos2dx/lib/Cocos2dxActivity.java | 4 ++++ .../src/org/cocos2dx/lib/Cocos2dxActivity.java | 4 ++++ cocos2dx/platform/android/CCEGLView_android.cpp | 2 +- cocos2dx/platform/android/Cocos2dJni.cpp | 16 ++++++++++++++++ cocos2dx/platform/android/Cocos2dJni.h | 13 +++++++------ .../src/org/cocos2dx/lib/Cocos2dxActivity.java | 4 ++++ 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/HelloLua/android/src/org/cocos2dx/lib/Cocos2dxActivity.java b/HelloLua/android/src/org/cocos2dx/lib/Cocos2dxActivity.java index 2246055fae..1a314cde23 100644 --- a/HelloLua/android/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/HelloLua/android/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -181,6 +181,10 @@ public class Cocos2dxActivity extends Activity{ public static String getCocos2dxPackageName(){ return packageName; } + + public static void terminateProcess(){ + android.os.Process.killProcess(android.os.Process.myPid()); + } @Override protected void onResume() { diff --git a/HelloWorld/android/src/org/cocos2dx/lib/Cocos2dxActivity.java b/HelloWorld/android/src/org/cocos2dx/lib/Cocos2dxActivity.java index 2246055fae..1a314cde23 100644 --- a/HelloWorld/android/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/HelloWorld/android/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -181,6 +181,10 @@ public class Cocos2dxActivity extends Activity{ public static String getCocos2dxPackageName(){ return packageName; } + + public static void terminateProcess(){ + android.os.Process.killProcess(android.os.Process.myPid()); + } @Override protected void onResume() { diff --git a/cocos2dx/platform/android/CCEGLView_android.cpp b/cocos2dx/platform/android/CCEGLView_android.cpp index 535c3d22d8..59ea027246 100644 --- a/cocos2dx/platform/android/CCEGLView_android.cpp +++ b/cocos2dx/platform/android/CCEGLView_android.cpp @@ -98,7 +98,7 @@ bool CCEGLView::isOpenGLReady() void CCEGLView::release() { - exit(0); + terminateProcessJNI(); } void CCEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate) diff --git a/cocos2dx/platform/android/Cocos2dJni.cpp b/cocos2dx/platform/android/Cocos2dJni.cpp index 81918e8c49..8df86aadbb 100644 --- a/cocos2dx/platform/android/Cocos2dJni.cpp +++ b/cocos2dx/platform/android/Cocos2dJni.cpp @@ -456,4 +456,20 @@ extern "C" return ret; } + + ////////////////////////////////////////////////////////////////////////// + // terminate the process + ////////////////////////////////////////////////////////////////////////// + void terminateProcessJNI() + { + TMethodJNI t; + + if (getMethodID(t + , "org/cocos2dx/lib/Cocos2dxActivity" + , "terminateProcess" + , "()V")) + { + t.env->CallStaticObjectMethod(t.classID, t.methodID); + } + } } diff --git a/cocos2dx/platform/android/Cocos2dJni.h b/cocos2dx/platform/android/Cocos2dJni.h index 62c78bd0b7..a65368c1f5 100644 --- a/cocos2dx/platform/android/Cocos2dJni.h +++ b/cocos2dx/platform/android/Cocos2dJni.h @@ -30,12 +30,13 @@ extern "C" { extern JavaVM *gJavaVM; - void enableAccelerometerJNI(); - void disableAccelerometerJNI(); - void showMessageBoxJNI(const char * pszMsg, const char * pszTitle); - void setKeyboardStateJNI(int bOpen); - char* getCurrentLanguageJNI(); - char* getPackageNameJNI(); + extern void enableAccelerometerJNI(); + extern void disableAccelerometerJNI(); + extern void showMessageBoxJNI(const char * pszMsg, const char * pszTitle); + extern void setKeyboardStateJNI(int bOpen); + extern char* getCurrentLanguageJNI(); + extern char* getPackageNameJNI(); + extern void terminateProcessJNI(); } #endif // __ANDROID_COCOS2D_JNI_H__ diff --git a/tests/test.android/src/org/cocos2dx/lib/Cocos2dxActivity.java b/tests/test.android/src/org/cocos2dx/lib/Cocos2dxActivity.java index 2246055fae..1a314cde23 100644 --- a/tests/test.android/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/tests/test.android/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -181,6 +181,10 @@ public class Cocos2dxActivity extends Activity{ public static String getCocos2dxPackageName(){ return packageName; } + + public static void terminateProcess(){ + android.os.Process.killProcess(android.os.Process.myPid()); + } @Override protected void onResume() { From d2d02e0c52dad968bd011cc7759c2e2a20c01944 Mon Sep 17 00:00:00 2001 From: Leon Date: Tue, 19 Jul 2011 16:54:42 +0800 Subject: [PATCH 2/3] fix compile error with android-ndk-r6 --- cocos2dx/platform/android/CCApplication_android.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cocos2dx/platform/android/CCApplication_android.cpp b/cocos2dx/platform/android/CCApplication_android.cpp index 82f86655a5..70fc59e10a 100644 --- a/cocos2dx/platform/android/CCApplication_android.cpp +++ b/cocos2dx/platform/android/CCApplication_android.cpp @@ -6,6 +6,8 @@ #include #include +#include + #define LOG_TAG "CCApplication_android Debug" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) From 5f1f63dabf0d1a4473047ea08f8a534ad3499b9d Mon Sep 17 00:00:00 2001 From: Leon Date: Wed, 20 Jul 2011 08:45:37 +0800 Subject: [PATCH 3/3] fix: passing std::string object to CCLOG --- cocos2dx/textures/CCTextureCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index 3ff1d12430..4c70f9af6d 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -328,7 +328,7 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path) } else { - CCLOG("cocos2d: Couldn't add PVRImage:%s in CCTextureCache",key); + CCLOG("cocos2d: Couldn't add PVRImage:%s in CCTextureCache",key.c_str()); } return tex;