From 615ad85d26f5b953322e7733d7c44121163819a8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 2 Apr 2024 11:26:22 +0400 Subject: [PATCH] Fix possible crash in notifications setup. Initial _account assignment triggered sync createManager(), which in case of native Windows notifications called ToastNotificationManager::CreateToastNotifier, which could enter qt-wndproc-message processing with QEvent::ApplicationActivated delivery and calling updateNonIdle() which called Window::Controller::account(), that wasn't yet set. --- Telegram/SourceFiles/main/main_domain.cpp | 6 ++++-- Telegram/SourceFiles/main/main_domain.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/main/main_domain.cpp b/Telegram/SourceFiles/main/main_domain.cpp index 26e01229f..cc6bd9457 100644 --- a/Telegram/SourceFiles/main/main_domain.cpp +++ b/Telegram/SourceFiles/main/main_domain.cpp @@ -32,11 +32,13 @@ Domain::Domain(const QString &dataName) : _dataName(dataName) , _local(std::make_unique(this, dataName)) { _active.changes( - ) | rpl::take(1) | rpl::start_with_next([] { + ) | rpl::take(1) | rpl::start_with_next([=] { // In case we had a legacy passcoded app we start settings here. Core::App().startSettingsAndBackground(); - Core::App().notifications().createManager(); + crl::on_main(this, [=] { + Core::App().notifications().createManager(); + }); }, _lifetime); _active.changes( diff --git a/Telegram/SourceFiles/main/main_domain.h b/Telegram/SourceFiles/main/main_domain.h index 1a39e8e7f..2e69222b9 100644 --- a/Telegram/SourceFiles/main/main_domain.h +++ b/Telegram/SourceFiles/main/main_domain.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "base/timer.h" +#include "base/weak_ptr.h" namespace Storage { class Domain; @@ -23,7 +24,7 @@ namespace Main { class Account; class Session; -class Domain final { +class Domain final : public base::has_weak_ptr { public: struct AccountWithIndex { int index = 0;