@@ -41,8 +41,11 @@ CWebView::~CWebView()
41
41
g_pCore->GetWebCore ()->SetFocusedWebView (nullptr );
42
42
}
43
43
44
+ // Make sure we don't dead lock the CEF render thread
45
+ ResumeCefThread ();
46
+
44
47
// Ensure that CefRefPtr::~CefRefPtr doesn't try to release it twice (it has already been released in CWebView::OnBeforeClose)
45
- m_pWebView = nullptr ;
48
+ m_pWebView = nullptr ;
46
49
47
50
OutputDebugLine (" CWebView::~CWebView" );
48
51
}
@@ -77,6 +80,9 @@ void CWebView::CloseBrowser()
77
80
// CefBrowserHost::CloseBrowser calls the destructor after the browser has been destroyed
78
81
m_bBeingDestroyed = true ;
79
82
83
+ // Make sure we don't dead lock the CEF render thread
84
+ ResumeCefThread ();
85
+
80
86
if (m_pWebView)
81
87
m_pWebView->GetHost ()->CloseBrowser (true );
82
88
}
@@ -200,7 +206,7 @@ void CWebView::UpdateTexture()
200
206
201
207
auto pSurface = m_pWebBrowserRenderItem->m_pD3DRenderTargetSurface ;
202
208
if (m_bBeingDestroyed || !pSurface)
203
- return ;
209
+ m_RenderData. changed = m_RenderData. popupShown = false ;
204
210
205
211
// Discard current buffer if size doesn't match
206
212
// This happens when resizing the browser as OnPaint is called asynchronously
@@ -281,6 +287,9 @@ void CWebView::UpdateTexture()
281
287
pSurface->UnlockRect ();
282
288
}
283
289
}
290
+
291
+ m_RenderData.cefThreadState = ECefThreadState::Running;
292
+ m_RenderData.cefThreadCv .notify_all ();
284
293
}
285
294
286
295
void CWebView::ExecuteJavascript (const SString& strJavascriptCode)
@@ -447,6 +456,8 @@ void CWebView::Resize(const CVector2D& size)
447
456
// Send resize event to CEF
448
457
if (m_pWebView)
449
458
m_pWebView->GetHost ()->WasResized ();
459
+
460
+ ResumeCefThread ();
450
461
}
451
462
452
463
CVector2D CWebView::GetSize ()
@@ -709,6 +720,10 @@ void CWebView::OnPaint(CefRefPtr<CefBrowser> browser, CefRenderHandler::PaintEle
709
720
m_RenderData.height = height;
710
721
m_RenderData.dirtyRects = dirtyRects;
711
722
m_RenderData.changed = true ;
723
+
724
+ // Wait for the main thread to handle drawing the texture
725
+ m_RenderData.cefThreadState = ECefThreadState::Wait;
726
+ m_RenderData.cefThreadCv .wait (lock, [&](){ return m_RenderData.cefThreadState == ECefThreadState::Running; });
712
727
}
713
728
714
729
// //////////////////////////////////////////////////////////////////
@@ -1069,3 +1084,14 @@ void CWebView::OnBeforeContextMenu(CefRefPtr<CefBrowser> browser, CefRefPtr<CefF
1069
1084
// Show no context menu
1070
1085
model->Clear ();
1071
1086
}
1087
+
1088
+ void CWebView::ResumeCefThread ()
1089
+ {
1090
+ {
1091
+ // It's recommended to unlock a mutex before the cv notifying to avoid a possible pessimization
1092
+ std::unique_lock<std::mutex> lock (m_RenderData.dataMutex );
1093
+ m_RenderData.cefThreadState = ECefThreadState::Running;
1094
+ }
1095
+
1096
+ m_RenderData.cefThreadCv .notify_all ();
1097
+ }
0 commit comments