diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index ce88bc621..c23cd8856 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -63,6 +63,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_domain.h" #include "storage/storage_databases.h" #include "storage/localstorage.h" +#include "payments/payments_checkout_process.h" #include "export/export_manager.h" #include "window/window_session_controller.h" #include "window/window_controller.h" @@ -149,6 +150,15 @@ Application::~Application() { _window = nullptr; _mediaView = nullptr; _notifications->clearAllFast(); + + // We must manually destroy all windows before going further. + // DestroyWindow on Windows (at least with an active WebView) enters + // event loop and invoke scheduled crl::on_main callbacks. + // + // For example Domain::removeRedundantAccounts() is called from + // Domain::finish() and there is a violation on Ensures(started()). + Payments::CheckoutProcess::ClearAll(); + _domain->finish(); Local::finish(); diff --git a/Telegram/SourceFiles/payments/payments_checkout_process.cpp b/Telegram/SourceFiles/payments/payments_checkout_process.cpp index 5b9292722..efbb02d2b 100644 --- a/Telegram/SourceFiles/payments/payments_checkout_process.cpp +++ b/Telegram/SourceFiles/payments/payments_checkout_process.cpp @@ -112,6 +112,10 @@ bool CheckoutProcess::TakePaymentStarted( return true; } +void CheckoutProcess::ClearAll() { + Processes.clear(); +} + void CheckoutProcess::RegisterPaymentStart( not_null process) { const auto i = Processes.find(process->_session); diff --git a/Telegram/SourceFiles/payments/payments_checkout_process.h b/Telegram/SourceFiles/payments/payments_checkout_process.h index 498e1385f..8dceffd2c 100644 --- a/Telegram/SourceFiles/payments/payments_checkout_process.h +++ b/Telegram/SourceFiles/payments/payments_checkout_process.h @@ -54,6 +54,7 @@ public: Fn reactivate); [[nodiscard]] static bool TakePaymentStarted( not_null item); + static void ClearAll(); CheckoutProcess( not_null peer, diff --git a/Telegram/SourceFiles/payments/ui/payments_panel.cpp b/Telegram/SourceFiles/payments/ui/payments_panel.cpp index d7155c513..e8923f2bb 100644 --- a/Telegram/SourceFiles/payments/ui/payments_panel.cpp +++ b/Telegram/SourceFiles/payments/ui/payments_panel.cpp @@ -501,7 +501,7 @@ bool Panel::createWebview() { _webview = nullptr; if (_webviewProgress) { hideWebviewProgress(); - if (!_progress->shown) { + if (_progress && !_progress->shown) { _progress = nullptr; } }