From 29cd94b9dba579adaa516bb5b7020fb388adf21b Mon Sep 17 00:00:00 2001 From: Ilya Melamed Date: Sun, 27 Oct 2019 11:28:57 +0200 Subject: [PATCH] Remove ExecuteOnBrowser wrapper on destroy Under certain conditions, when browser source scene items are removed in a loop, CEF UI thread may hang waiting for previous invocations of ExecuteOnBrowser() to complete resulting in a deadlock. Since CefBrowserHost::WasHidden() and CefBrowserHost::CloseBrowser() are not required to be called on a certain thread, removing ExecuteOnBrowser() altogether preserves the functionality, eliminates the deadlock and simplifies the code. --- obs-browser-source.cpp | 39 ++++++++++++++++++--------------------- obs-browser-source.hpp | 2 +- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/obs-browser-source.cpp b/obs-browser-source.cpp index 1635994e9..4cb9d2b18 100644 --- a/obs-browser-source.cpp +++ b/obs-browser-source.cpp @@ -185,27 +185,24 @@ bool BrowserSource::CreateBrowser() }); } -void BrowserSource::DestroyBrowser(bool async) +void BrowserSource::DestroyBrowser() { - ExecuteOnBrowser( - [](CefRefPtr cefBrowser) { - CefRefPtr client = - cefBrowser->GetHost()->GetClient(); - BrowserClient *bc = - reinterpret_cast(client.get()); - if (bc) { - bc->bs = nullptr; - } + if (!cefBrowser) + return; - /* - * This stops rendering - * http://magpcss.org/ceforum/viewtopic.php?f=6&t=12079 - * https://bitbucket.org/chromiumembedded/cef/issues/1363/washidden-api-got-broken-on-branch-2062) - */ - cefBrowser->GetHost()->WasHidden(true); - cefBrowser->GetHost()->CloseBrowser(true); - }, - async); + CefRefPtr client = cefBrowser->GetHost()->GetClient(); + BrowserClient *bc = reinterpret_cast(client.get()); + if (bc) { + bc->bs = nullptr; + } + + /* + * This stops rendering + * http://magpcss.org/ceforum/viewtopic.php?f=6&t=12079 + * https://bitbucket.org/chromiumembedded/cef/issues/1363/washidden-api-got-broken-on-branch-2062) + */ + cefBrowser->GetHost()->WasHidden(true); + cefBrowser->GetHost()->CloseBrowser(true); cefBrowser = nullptr; } @@ -330,7 +327,7 @@ void BrowserSource::SetShowing(bool showing) if (showing) { Update(); } else { - DestroyBrowser(true); + DestroyBrowser(); } } else { #if EXPERIMENTAL_SHARED_TEXTURE_SUPPORT_ENABLED @@ -453,7 +450,7 @@ void BrowserSource::Update(obs_data_t *settings) obs_source_set_audio_active(source, reroute_audio); } - DestroyBrowser(true); + DestroyBrowser(); DestroyTextures(); ClearAudioStreams(); if (!shutdown_on_invisible || obs_source_showing(source)) diff --git a/obs-browser-source.hpp b/obs-browser-source.hpp index 8dbfd83ad..2f9a4b0a6 100644 --- a/obs-browser-source.hpp +++ b/obs-browser-source.hpp @@ -82,7 +82,7 @@ struct BrowserSource { /* ---------------------------- */ bool CreateBrowser(); - void DestroyBrowser(bool async = false); + void DestroyBrowser(); void ClearAudioStreams(); void ExecuteOnBrowser(BrowserFunc func, bool async = false);