-
Notifications
You must be signed in to change notification settings - Fork 137
Fix ButtonClicker random crash issue [ the crash happens on 64 bit gpg sdk ] #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,15 +105,14 @@ void Engine::InitGooglePlayGameServices() { | |
| * | ||
| */ | ||
| void Engine::OnAuthActionStarted(gpg::AuthOperation op) { | ||
| startup_mutex_.lock(); | ||
| if (!initialized_resources_) return; | ||
|
|
||
| ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([this, op]() { | ||
| EnableUI(false); | ||
| authorizing_ = true; | ||
| if (op == gpg::AuthOperation::SIGN_IN) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you keep the log messages? They help diagnose issues which there always are with authentication.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed a couple of LOG messages from sample to make it clean. when UI is up, it is displayed UI page at the bottom in status_text. so we could make it a little clean in logcat
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But when there is a problem, we ask for a log so we can see what is going on - so now we can't see what is going on. Please put them back. |
||
| LOGI("Signing in to GPG"); | ||
| status_text_->SetAttribute("Text", "Signing In..."); | ||
| } else { | ||
| LOGI("Signing out from GPG"); | ||
| status_text_->SetAttribute("Text", "Signing Out..."); | ||
| } | ||
| }); | ||
|
|
@@ -135,17 +134,19 @@ void Engine::OnAuthActionFinished(gpg::AuthOperation op, | |
| } | ||
| }); | ||
| } | ||
|
|
||
| if (!initialized_resources_) return; | ||
|
|
||
|
|
||
| if (!initialized_resources_) { | ||
| startup_mutex_.unlock(); | ||
| return; | ||
| } | ||
| ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([this, status]() { | ||
| EnableUI(true); | ||
| authorizing_ = false; | ||
| button_sign_in_->SetAttribute( | ||
| "Text", gpg::IsSuccess(status) ? "Sign Out" : "Sign In"); | ||
|
|
||
| status_text_->SetAttribute( | ||
| "Text", gpg::IsSuccess(status) ? "Signed In" : "Signed Out"); | ||
| startup_mutex_.unlock(); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -560,8 +561,14 @@ void Engine::LeaveGame() { | |
| * invoking jui_helper functions to create java UIs | ||
| */ | ||
| void Engine::InitUI() { | ||
| // The window initialization | ||
| jui_helper::JUIWindow::Init(app_->activity, JUIHELPER_CLASS_NAME); | ||
|
|
||
| // Show toast with app label | ||
| ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([]() { | ||
| if(NULL == jui_helper::JUIWindow::GetInstance()->GetContext()) { | ||
| return; | ||
| } | ||
| jui_helper::JUIToast toast( | ||
| ndk_helper::JNIHelper::GetInstance()->GetAppLabel()); | ||
| toast.Show(); | ||
|
|
@@ -572,9 +579,6 @@ void Engine::InitUI() { | |
| // UIs. | ||
| // | ||
|
|
||
| // The window initialization | ||
| jui_helper::JUIWindow::Init(app_->activity, JUIHELPER_CLASS_NAME); | ||
|
|
||
| // | ||
| // Buttons | ||
| // | ||
|
|
@@ -586,7 +590,6 @@ void Engine::InitUI() { | |
| jui_helper::LAYOUT_PARAMETER_TRUE); | ||
| button_sign_in_->SetCallback([this](jui_helper::JUIView *view, | ||
| const int32_t message) { | ||
| LOGI("button_sign_in_ click: %d", message); | ||
| if (message == jui_helper::JUICALLBACK_BUTTON_UP) { | ||
| if (service_->IsAuthorized()) { | ||
| service_->SignOut(); | ||
|
|
@@ -647,7 +650,6 @@ void Engine::InitUI() { | |
| // Init play game services | ||
| InitGooglePlayGameServices(); | ||
|
|
||
| if (authorizing_) EnableUI(false); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -669,7 +671,6 @@ void Engine::SetParameters(jui_helper::JUIButton *button, | |
| * Enable/Disable management UI | ||
| */ | ||
| void Engine::EnableUI(bool enable) { | ||
| LOGI("Updating UI:%d", enable); | ||
| ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([this, enable]() { | ||
| button_sign_in_->SetAttribute("Enabled", enable); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,13 +147,13 @@ class Engine : public gpg::IRealTimeEventListener { | |
| // in OnRoomStatusChanged() | ||
| int32_t score_counter_; // Score counter of local player | ||
| bool playing_; // Am I playing a game? | ||
| bool authorizing_; // Am I signing in to gpg service? | ||
| std::string self_id_; // Local player's ID | ||
| double start_time_; // Game start time | ||
|
|
||
| // synchronization primitive to synchronize | ||
| // UIThread, Timer thread and gpg callback thread | ||
| mutable std::mutex mutex_; | ||
| mutable std::mutex startup_mutex_; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a comment on why 2 mutex are needed? It seems like 1 should be ok?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one is just for start up code: taking conservative way not to make a big change to the existing code. |
||
|
|
||
| // Renderer of a teapot | ||
| TeapotRenderer renderer_; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,6 @@ | |
| Engine::Engine() | ||
| : initialized_resources_(false), | ||
| has_focus_(false), | ||
| authorizing_(false), | ||
| app_(nullptr), | ||
| dialog_(nullptr), | ||
| textViewFPS_(nullptr), | ||
|
|
@@ -61,10 +60,12 @@ void Engine::UnloadResources() { renderer_.Unload(); } | |
| */ | ||
| int Engine::InitDisplay(const int32_t cmd) { | ||
| if (!initialized_resources_) { | ||
| startup_mutex_.lock(); | ||
| gl_context_->Init(app_->window); | ||
| InitUI(); | ||
| LoadResources(); | ||
| initialized_resources_ = true; | ||
| startup_mutex_.unlock(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you catch exceptions to make sure the mutex gets unlocked?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is good point. if there is exception in native code, it crashes and there is not any catcher here. I think java code handles lot of exceptions; in side native code, I do not see too much yet. |
||
| } else { | ||
| // initialize OpenGL ES and EGL | ||
| if (EGL_SUCCESS != gl_context_->Resume(app_->window)) { | ||
|
|
@@ -192,7 +193,6 @@ int32_t Engine::HandleInput(android_app *app, AInputEvent *event) { | |
| */ | ||
| void Engine::HandleCmd(struct android_app *app, int32_t cmd) { | ||
| Engine *eng = (Engine *)app->userData; | ||
| LOGI("message %d", cmd); | ||
| switch (cmd) { | ||
| case APP_CMD_SAVE_STATE: | ||
| break; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we keep this at 9?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, sure