From b415b293cffd1e9902d9d2cd75c11f20c2429be0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 1 Feb 2022 15:24:28 +0300 Subject: [PATCH] Fix crash from background access to style::icon-s. --- Telegram/SourceFiles/ui/chat/chat_theme.cpp | 12 ++++++++++-- Telegram/SourceFiles/ui/chat/chat_theme.h | 1 + Telegram/SourceFiles/ui/chat/message_bubble.cpp | 13 ++++++++----- Telegram/SourceFiles/ui/chat/message_bubble.h | 1 + .../window/window_session_controller.cpp | 1 + 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/ui/chat/chat_theme.cpp b/Telegram/SourceFiles/ui/chat/chat_theme.cpp index 8bfdc422b9..397df24633 100644 --- a/Telegram/SourceFiles/ui/chat/chat_theme.cpp +++ b/Telegram/SourceFiles/ui/chat/chat_theme.cpp @@ -444,7 +444,8 @@ void ChatTheme::setBubblesBackground(QImage image) { _bubblesBackgroundPrepared = std::move(image); if (_bubblesBackgroundPrepared.isNull()) { _bubblesBackgroundPattern = nullptr; - _repaintBackgroundRequests.fire({}); + // setBubblesBackground called only from background thread. + //_repaintBackgroundRequests.fire({}); return; } _bubblesBackground = CacheBackground({ @@ -459,7 +460,14 @@ void ChatTheme::setBubblesBackground(QImage image) { _bubblesBackgroundPattern = PrepareBubblePattern(palette()); } _bubblesBackgroundPattern->pixmap = _bubblesBackground.pixmap; - _repaintBackgroundRequests.fire({}); + // setBubblesBackground called only from background thread. + //_repaintBackgroundRequests.fire({}); +} + +void ChatTheme::finishCreateOnMain() { + if (_bubblesBackgroundPattern) { + FinishBubblePatternOnMain(_bubblesBackgroundPattern.get()); + } } ChatPaintContext ChatTheme::preparePaintContext( diff --git a/Telegram/SourceFiles/ui/chat/chat_theme.h b/Telegram/SourceFiles/ui/chat/chat_theme.h index c99a99e501..31f766e2f8 100644 --- a/Telegram/SourceFiles/ui/chat/chat_theme.h +++ b/Telegram/SourceFiles/ui/chat/chat_theme.h @@ -163,6 +163,7 @@ public: [[nodiscard]] const BubblePattern *bubblesBackgroundPattern() const { return _bubblesBackgroundPattern.get(); } + void finishCreateOnMain(); // Called on_main after setBubblesBackground. [[nodiscard]] ChatPaintContext preparePaintContext( not_null st, diff --git a/Telegram/SourceFiles/ui/chat/message_bubble.cpp b/Telegram/SourceFiles/ui/chat/message_bubble.cpp index 47a8998173..c7f58d7ce2 100644 --- a/Telegram/SourceFiles/ui/chat/message_bubble.cpp +++ b/Telegram/SourceFiles/ui/chat/message_bubble.cpp @@ -266,11 +266,6 @@ std::unique_ptr PrepareBubblePattern( }; addShadow(result->corners[2]); addShadow(result->corners[3]); - result->tailLeft = st::historyBubbleTailOutLeft.instance(Qt::white); - result->tailRight = st::historyBubbleTailOutRight.instance(Qt::white); - result->tailCache = QImage( - result->tailLeft.size(), - QImage::Format_ARGB32_Premultiplied); result->cornerTopCache = QImage( result->corners[0].size(), QImage::Format_ARGB32_Premultiplied); @@ -280,6 +275,14 @@ std::unique_ptr PrepareBubblePattern( return result; } +void FinishBubblePatternOnMain(not_null pattern) { + pattern->tailLeft = st::historyBubbleTailOutLeft.instance(Qt::white); + pattern->tailRight = st::historyBubbleTailOutRight.instance(Qt::white); + pattern->tailCache = QImage( + pattern->tailLeft.size(), + QImage::Format_ARGB32_Premultiplied); +} + void PaintBubble(Painter &p, const SimpleBubble &args) { if (!args.selected && args.outbg diff --git a/Telegram/SourceFiles/ui/chat/message_bubble.h b/Telegram/SourceFiles/ui/chat/message_bubble.h index c7f8edb103..71ebf5873a 100644 --- a/Telegram/SourceFiles/ui/chat/message_bubble.h +++ b/Telegram/SourceFiles/ui/chat/message_bubble.h @@ -33,6 +33,7 @@ struct BubblePattern { [[nodiscard]] std::unique_ptr PrepareBubblePattern( not_null st); +void FinishBubblePatternOnMain(not_null pattern); struct SimpleBubble { not_null st; diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index fff1fc4f09..4e49a1fa93 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -1632,6 +1632,7 @@ void SessionController::cacheChatTheme( this, result = std::make_shared(std::move(descriptor)) ]() mutable { + result->finishCreateOnMain(); cacheChatThemeDone(std::move(result)); }); });