1
0

Fix crash on exit

This commit is contained in:
Scott E. Graves
2017-04-28 16:50:34 -05:00
parent 1c4a6b79fe
commit 15fae63d0d
2 changed files with 18 additions and 10 deletions

View File

@@ -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.

View File

@@ -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))