Android: fix deadlock for update nativeWindow (#13709)

* Android:   fix deadlock for update nativeWindow
This commit is contained in:
bofeng-song
2022-12-07 15:40:05 +08:00
committed by GitHub
parent 9ca363e821
commit 6df0caca16
2 changed files with 9 additions and 2 deletions
@@ -60,12 +60,16 @@ void SystemWindow::copyTextToClipboard(const ccstd::string &text) {
void SystemWindow::setWindowHandle(void *handle) {
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
std::lock_guard lock(_handleMutex);
//The getWindowHandle interface may have been called earlier, causing _handleMutex to be occupied all the time.
bool lockSuccess = _handleMutex.try_lock();
bool needNotify = _windowHandle == nullptr;
_windowHandle = handle;
if (needNotify) {
_windowHandlePromise.set_value();
}
if (lockSuccess) {
_handleMutex.unlock();
}
#else
_windowHandle = handle;
#endif