Fix crash (using freed memory) changing Screen/UI Scaling/Theme for a very specific ColorBar/PaletteView case (fix #3906)

We were able to reproduce this putting the black border of the
ColorBar's PaletteView touching its viewport, and changing from Screen
Scaling=200% & UI Scaling=100% to Screen Scaling=100% & UI
Scaling=200% (with the memory sanitizer on).
This commit is contained in:
David Capello 2023-05-31 14:57:37 -03:00
parent fa79619c16
commit 2f54bcaf37

View File

@ -1696,7 +1696,12 @@ void Widget::onBroadcastMouseMessage(const gfx::Point& screenPos,
void Widget::onInitTheme(InitThemeEvent& ev)
{
for (auto child : children())
// Create a copy of the children list and iterate it, just in case a
// initTheme() modifies this list (e.g. this can happen in some
// strange cases with viewports, where scrollbars are added/removed
// while we init the theme if the UI scale changes).
auto children = m_children;
for (auto child : children)
child->initTheme();
if (m_theme) {