Skip to content

Commit 2b8606e

Browse files
committed
fix teapot random crash
1 parent 1263c48 commit 2b8606e

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

samples-android/ButtonClicker/jni/Application.mk

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
APP_PLATFORM := android-22
2-
#APP_ABI := all
3-
#APP_ABI := armeabi-v7a
4-
APP_STL := arm64-v8a
5-
2+
APP_ABI := armeabi-v7a
63
APP_STL := c++_static
74

85
APP_CPPFLAGS := -std=c++11

samples-android/ButtonClicker/jni/ButtonClickerNativeActivity.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ void Engine::InitGooglePlayGameServices() {
105105
*
106106
*/
107107
void Engine::OnAuthActionStarted(gpg::AuthOperation op) {
108-
startup_mutex_.lock();
108+
if(!initialized_resources_) {
109+
return;
110+
}
111+
109112
ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([this, op]() {
110113
EnableUI(false);
111114
if (op == gpg::AuthOperation::SIGN_IN) {
@@ -133,14 +136,17 @@ void Engine::OnAuthActionFinished(gpg::AuthOperation op,
133136
});
134137
}
135138

139+
if(!initialized_resources_) {
140+
return;
141+
}
142+
136143
ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([this, status]() {
137144
EnableUI(true);
138145
button_sign_in_->SetAttribute(
139146
"Text", gpg::IsSuccess(status) ? "Sign Out" : "Sign In");
140147

141148
status_text_->SetAttribute(
142149
"Text", gpg::IsSuccess(status) ? "Signed In" : "Signed Out");
143-
startup_mutex_.unlock();
144150
});
145151
}
146152

samples-android/ButtonClicker/jni/ButtonClickerNativeActivity.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ class Engine : public gpg::IRealTimeEventListener {
153153
// synchronization primitive to synchronize
154154
// UIThread, Timer thread and gpg callback thread
155155
mutable std::mutex mutex_;
156-
mutable std::mutex startup_mutex_;
157156

158157
// Renderer of a teapot
159158
TeapotRenderer renderer_;

samples-android/ButtonClicker/jni/ButtonClickerNativeActivity_Engine.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,10 @@ void Engine::UnloadResources() { renderer_.Unload(); }
6060
*/
6161
int Engine::InitDisplay(const int32_t cmd) {
6262
if (!initialized_resources_) {
63-
startup_mutex_.lock();
6463
gl_context_->Init(app_->window);
6564
InitUI();
6665
LoadResources();
6766
initialized_resources_ = true;
68-
startup_mutex_.unlock();
6967
} else {
7068
// initialize OpenGL ES and EGL
7169
if (EGL_SUCCESS != gl_context_->Resume(app_->window)) {

samples-android/Teapot/jni/NativeGameActivity.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ Engine::~Engine() {
112112
}
113113

114114
void Engine::InitUI() {
115+
// The window is being shown, get it ready.
116+
jui_helper::JUIWindow::Init(app_->activity, JUIHELPER_CLASS_NAME);
117+
115118
// Show toast with app label
116119
ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([]() {
117120
jui_helper::JUIToast toast(
118121
ndk_helper::JNIHelper::GetInstance()->GetAppLabel());
119122
toast.Show();
120123
});
121124

122-
// The window is being shown, get it ready.
123-
jui_helper::JUIWindow::Init(app_->activity, JUIHELPER_CLASS_NAME);
124-
125125
//
126126
// Buttons
127127
//
@@ -472,6 +472,9 @@ void Engine::UpdateFPS(float fps) {
472472
}
473473

474474
void Engine::OnAuthActionStarted(gpg::AuthOperation op) {
475+
if (!initialized_resources_) {
476+
return;
477+
}
475478
ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([this, op]() {
476479
if (status_text_) {
477480
if (op == gpg::AuthOperation::SIGN_IN) {
@@ -485,6 +488,10 @@ void Engine::OnAuthActionStarted(gpg::AuthOperation op) {
485488

486489
void Engine::OnAuthActionFinished(gpg::AuthOperation op,
487490
gpg::AuthStatus status) {
491+
if (!initialized_resources_) {
492+
return;
493+
}
494+
488495
ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([this, status]() {
489496
if (status == gpg::AuthStatus::VALID) {
490497
jui_helper::JUIToast toast("Signed In.");

0 commit comments

Comments
 (0)