Skip to content

Commit e9a359c

Browse files
committed
fix Destroy() and captureLayout's update loop to avoid conflict
1 parent b24244b commit e9a359c

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

libwebview/src/main/java/com/tlab/libwebview/UnityConnect.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ public class UnityConnect extends Fragment {
105105
//
106106
//
107107

108+
private boolean m_captureLayoutLoopKeepAlive = true;
109+
private final Object m_captureLayoutLoopMutex = new Object();
110+
111+
// ---------------------------------------------------------------------------------------------------------
112+
//
113+
//
114+
108115
private enum DownloadOption {
109116
applicationFolder, downloadFolder
110117
}
@@ -830,8 +837,10 @@ public void onReceive(Context context, Intent intent) {
830837
}
831838

832839
new Thread(() -> {
833-
while (m_captureLayout != null) {
834-
m_captureLayout.postInvalidate();
840+
while (m_captureLayoutLoopKeepAlive) {
841+
synchronized (m_captureLayoutLoopMutex) {
842+
m_captureLayout.postInvalidate();
843+
}
835844
try {
836845
Thread.sleep(1000 / m_fps);
837846
} catch (InterruptedException e) {
@@ -881,10 +890,18 @@ public void Destroy() {
881890
return;
882891
}
883892

884-
m_webview.stopLoading();
893+
synchronized (m_captureLayoutLoopMutex) {
894+
m_captureLayoutLoopKeepAlive = false;
895+
}
896+
885897
m_frameLayout.removeAllViews();
886-
m_webview.destroy();
887-
m_webview = null;
898+
m_frameLayout = null;
899+
900+
m_webview.post(() -> {
901+
m_webview.stopLoading();
902+
m_webview.destroy();
903+
m_webview = null;
904+
});
888905

889906
a.unregisterReceiver(m_onDownloadComplete);
890907
a

0 commit comments

Comments
 (0)