Fix crash on exit
This commit is contained in:
@@ -66,6 +66,7 @@ private:
|
||||
static void ExecuteSetter(CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> obj, const SString& method, CefRefPtr<CefV8Value> value);
|
||||
void ShutdownServices(CefRefPtr<CefBrowser> browser);
|
||||
void SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const Api::CSiaCurl& siaCurl, Api::CSiaDriveConfig* siaDriveConfig);
|
||||
void ReleaseObjects(CefRefPtr<CefBrowser> browser);
|
||||
|
||||
private:
|
||||
// Include the default reference counting implementation.
|
||||
|
@@ -401,6 +401,7 @@ void CSiaDriveApp::OnContextInitialized()
|
||||
|
||||
void CSiaDriveApp::ShutdownServices(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
_appStarted = false;
|
||||
{
|
||||
auto context = browser->GetMainFrame()->GetV8Context();
|
||||
context->Enter();
|
||||
@@ -412,12 +413,11 @@ void CSiaDriveApp::ShutdownServices(CefRefPtr<CefBrowser> browser)
|
||||
displayShutdownWindow->ExecuteFunctionWithContext(context, nullptr, args);
|
||||
context->Exit();
|
||||
}
|
||||
|
||||
std::thread([this, browser]() {
|
||||
if (_refreshThread)
|
||||
{
|
||||
_appStarted = false;
|
||||
_refreshThread->StopAutoThread();
|
||||
_refreshThread.reset(nullptr);
|
||||
}
|
||||
|
||||
if (_siaDrive)
|
||||
@@ -425,27 +425,34 @@ void CSiaDriveApp::ShutdownServices(CefRefPtr<CefBrowser> browser)
|
||||
_siaDrive->Unmount();
|
||||
}
|
||||
|
||||
if (_siaDriveConfig && _siaDriveConfig->GetLockWalletOnExit())
|
||||
{
|
||||
_siaApi->GetWallet()->Lock();
|
||||
}
|
||||
|
||||
if (_siaApi)
|
||||
{
|
||||
_siaApi->StopBackgroundRefresh();
|
||||
}
|
||||
|
||||
if (_siaDriveConfig && _siaDriveConfig->GetLockWalletOnExit())
|
||||
{
|
||||
_siaApi->GetWallet()->Lock();
|
||||
}
|
||||
|
||||
_refreshThread.reset(nullptr);
|
||||
_siaDrive.reset(nullptr);
|
||||
_siaApi.reset(nullptr);
|
||||
_siaCurl.reset(nullptr);
|
||||
CEventSystem::EventSystem.Stop();
|
||||
_siaDriveConfig.reset();
|
||||
|
||||
CEventSystem::EventSystem.Stop();
|
||||
|
||||
CefRefPtr<CefProcessMessage> msg = CefProcessMessage::Create("shutdownServicesComplete");
|
||||
browser->SendProcessMessage(PID_BROWSER, msg);
|
||||
CefPostTask(TID_RENDERER, base::Bind(&CSiaDriveApp::ReleaseObjects, this, browser));
|
||||
}).detach();
|
||||
}
|
||||
|
||||
void CSiaDriveApp::ReleaseObjects(CefRefPtr<CefBrowser> browser)
|
||||
{
|
||||
CefRefPtr<CefProcessMessage> msg = CefProcessMessage::Create("shutdownServicesComplete");
|
||||
browser->SendProcessMessage(PID_BROWSER, msg);
|
||||
}
|
||||
|
||||
void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig)
|
||||
{
|
||||
if (CefCurrentlyOn(TID_RENDERER))
|
||||
|
Reference in New Issue
Block a user