From d369d988b0e572cddae5014a7ed6d415353afeb8 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 6 May 2025 23:25:21 +0300 Subject: [PATCH] Fixed possible crashed on local zoom of charts in stats. --- Telegram/SourceFiles/statistics/chart_widget.cpp | 13 +++++++++---- Telegram/SourceFiles/statistics/chart_widget.h | 1 + Telegram/lib_ui | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/statistics/chart_widget.cpp b/Telegram/SourceFiles/statistics/chart_widget.cpp index 4e7534d9a3..7123b186cd 100644 --- a/Telegram/SourceFiles/statistics/chart_widget.cpp +++ b/Telegram/SourceFiles/statistics/chart_widget.cpp @@ -1275,9 +1275,13 @@ void ChartWidget::processLocalZoom(int xIndex) { if (_footer->isHidden()) { return; } + _localZoomLifetime.destroy(); const auto wasZoom = _footer->xPercentageLimits(); - const auto header = Ui::CreateChild
(this); + const auto headerOwned + = _localZoomLifetime.make_state>( + base::make_unique_q
(this)); + const auto header = headerOwned->get(); header->show(); _header->geometryValue( ) | rpl::start_with_next([=](const QRect &g) { @@ -1290,7 +1294,8 @@ void ChartWidget::processLocalZoom(int xIndex) { setAttribute(Qt::WA_TransparentForMouseEvents, !value); }; - const auto mouseTrackingLifetime = std::make_shared(); + const auto mouseTrackingLifetime + = _localZoomLifetime.make_state(); _chartView->setUpdateCallback([=] { _chartArea->update(); }); const auto createMouseTracking = [=] { _chartArea->setMouseTracking(true); @@ -1322,7 +1327,7 @@ void ChartWidget::processLocalZoom(int xIndex) { zoomOutButton->setTextTransform( Ui::RoundButton::TextTransform::NoTransform); zoomOutButton->setClickedCallback([=] { - auto lifetime = std::make_shared(); + auto lifetime = _localZoomLifetime.make_state(); const auto animation = lifetime->make_state(); const auto currentXPercentage = _footer->xPercentageLimits(); animation->start([=](float64 value) { @@ -1365,7 +1370,7 @@ void ChartWidget::processLocalZoom(int xIndex) { }; { - auto lifetime = std::make_shared(); + auto lifetime = _localZoomLifetime.make_state(); const auto animation = lifetime->make_state(); _chartView->maybeLocalZoom({ _chartData, Type::Prepare }); animation->start([=](float64 value) { diff --git a/Telegram/SourceFiles/statistics/chart_widget.h b/Telegram/SourceFiles/statistics/chart_widget.h index 5021603fff..66e0dff961 100644 --- a/Telegram/SourceFiles/statistics/chart_widget.h +++ b/Telegram/SourceFiles/statistics/chart_widget.h @@ -175,6 +175,7 @@ private: rpl::event_stream _zoomRequests; rpl::lifetime _waitingSizeLifetime; + rpl::lifetime _localZoomLifetime; }; diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 0b324ce83c..369d8b5172 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 0b324ce83c219c817fdd3c94a23b55fec6fec637 +Subproject commit 369d8b5172b6f70a3a9b2363cfa0f4fc5f620f56