I have a situation where I would like to update CEF (using 4103 / 83.0.4103.97) within an existing message pump so I'm using CefDoMessageLoopWork for this. However, I'm having trouble shutting down CEF properly.
I need to explicitely close the browser before calling CefShutdown, otherwise I'm getting an assertion and a crash when calling CefShutdown in:
- Code: Select all
libcef.dll!logging::LogMessage::~LogMessage() Line 953 C++
libcef.dll!cef_log(const char * file, int line, int severity, const char * message) Line 335 C++
[External Code]
> libcef.dll!CefAudioHandlerCToCpp::OnAudioStreamStopped(scoped_refptr<CefBrowser> browser) Line 113 C++
libcef.dll!CefBrowserHostImpl::DestroyBrowser() Line 1535 C++
libcef.dll!CefBrowserInfoManager::DestroyAllBrowsers() Line 352 C++
libcef.dll!CefContext::FinishShutdownOnUIThread(base::WaitableEvent * uithread_shutdown_event) Line 680 C++
libcef.dll!CefContext::Shutdown() Line 567 C++
libcef.dll!CefShutdown() Line 351 C++
with the log message "[FATAL:shutdown_checker.cc(52)] Check failed: !IsCefShutdown(). Object reference incorrectly held at CefShutdown"
So I'm closing the browser like this:
- Code: Select all
browser->GetHost()->CloseBrowser(true)
I also need to wait for this operation to complete or the assertion will still be false. Currently I'm waiting for the callback CefLifeSpanHandler::OnBeforeClose where I'm clearing my browser variable. However, I also need to keep updating CEF while doing so:
- Code: Select all
WINASSERT(CefCurrentlyOn(TID_UI));
if (browser != nullptr)
{
browser->GetHost()->CloseBrowser(true);
}
for (int attempts = 0; browser != nullptr && attempts < 1000; ++attempts)
{
Sleep(1);
CefDoMessageLoopWork();
}
Clearly this isn't a good solution, but this is the most responsive shutdown I could achieve so far.
Can anyone point me into a better direction? Can I avoid closing the browser without tripping that shutdown assertion or is there a better way to close it?
Thanks.