From 5b4f70ff96caec77aede8f0c0ea3765c37778ec2 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 28 Jun 2017 10:06:52 +0300 Subject: [PATCH] Fix crash in layer stack unwinding. --- Telegram/SourceFiles/layerwidget.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Telegram/SourceFiles/layerwidget.cpp b/Telegram/SourceFiles/layerwidget.cpp index 7789569c17..9f7f355af2 100644 --- a/Telegram/SourceFiles/layerwidget.cpp +++ b/Telegram/SourceFiles/layerwidget.cpp @@ -717,6 +717,15 @@ void LayerStackWidget::onLayerDestroyed(QObject *obj) { } LayerStackWidget::~LayerStackWidget() { + // We must destroy all layers before we destroy LayerStackWidget. + // Some layers in destructor call layer-related methods, like hiding + // other layers, that call methods of LayerStackWidget and access + // its fields, so if it is destroyed already everything crashes. + for (auto layer : base::take(_layers)) { + layer->setClosing(); + layer->hide(); + delete layer; + } if (App::wnd()) App::wnd()->noLayerStack(this); }