Fix crash from background access to style::icon-s.

This commit is contained in:
John Preston 2022-02-01 15:24:28 +03:00
parent 3a1bb1966d
commit b415b293cf
5 changed files with 21 additions and 7 deletions

View File

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

View File

@ -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<const ChatStyle*> st,

View File

@ -266,11 +266,6 @@ std::unique_ptr<BubblePattern> 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<BubblePattern> PrepareBubblePattern(
return result;
}
void FinishBubblePatternOnMain(not_null<BubblePattern*> 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

View File

@ -33,6 +33,7 @@ struct BubblePattern {
[[nodiscard]] std::unique_ptr<BubblePattern> PrepareBubblePattern(
not_null<const style::palette*> st);
void FinishBubblePatternOnMain(not_null<BubblePattern*> pattern);
struct SimpleBubble {
not_null<const ChatStyle*> st;

View File

@ -1632,6 +1632,7 @@ void SessionController::cacheChatTheme(
this,
result = std::make_shared<Ui::ChatTheme>(std::move(descriptor))
]() mutable {
result->finishCreateOnMain();
cacheChatThemeDone(std::move(result));
});
});