From a4fc3735c71b349b790cb1e3d9ccb56810ee24b7 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 22 May 2021 14:18:14 -0300 Subject: [PATCH] Fix crash setting theme in certain cases Mainly when changing ui::View children (where a view changes its children onInitTheme() function, e.g. adding/removing scrollbar). --- src/ui/intern.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/ui/intern.cpp b/src/ui/intern.cpp index 96d490d61..fac0e1332 100644 --- a/src/ui/intern.cpp +++ b/src/ui/intern.cpp @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2021 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This file is released under the terms of the MIT license. @@ -58,10 +58,22 @@ void reinitThemeForAllWidgets() { assert_ui_thread(); - // Reinitialize the theme of each widget + // Reinitialize the theme in this order: + // 1. From the manager to children (windows and children widgets in + // the window etc.) auto theme = get_theme(); - for (auto widget : *widgets) - widget->setTheme(theme); + if (auto man = Manager::getDefault()) { + man->setTheme(theme); + } + + // 2. If some other widget wasn't updated (e.g. is outside the + // hierarchy of widgets), we update the theme for that one too. + // + // TODO Is this really needed? + for (auto widget : *widgets) { + if (theme != widget->theme()) + widget->setTheme(theme); + } } } // namespace details