Fix crash when trying to access a property of a Style which is nullptr (fix #4015)

Before this fix, an incomplete custom theme or an outdated official
theme could cause a crash during Aseprite startup.

This fix does not alert the artist the problem of the theme.
Simply avoid the crash.
This commit is contained in:
Gaspar Capello 2024-02-21 14:44:40 -03:00 committed by David Capello
parent 078dac28d7
commit f22603caea
5 changed files with 19 additions and 7 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020-2023 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -108,7 +108,7 @@ namespace app {
if (it != m_styles.end())
return it->second;
else
return nullptr;
return getDefaultStyle();
}
SkinPartPtr getPartById(const std::string& id) const {

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018-2023 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -125,6 +125,9 @@ Grid::Info Grid::getChildInfo(Widget* child)
void Grid::setStyle(Style* style)
{
ASSERT(style);
if (!style)
style = Theme::getDefaultStyle();
Widget::setStyle(style);
setGap(style->gap());
}

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -142,6 +142,9 @@ Theme::~Theme()
set_theme(nullptr, guiscale());
}
// static
ui::Style Theme::m_defaultStyle(nullptr);
void Theme::regenerateTheme()
{
set_mouse_cursor(kNoCursor);

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (Cg) 2020-2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -141,6 +141,8 @@ namespace ui {
static void drawTextBox(Graphics* g, const Widget* textbox,
int* w, int* h, gfx::Color bg, gfx::Color fg);
static ui::Style* getDefaultStyle() { return &m_defaultStyle; }
protected:
virtual void onRegenerateTheme() = 0;
@ -165,6 +167,8 @@ namespace ui {
gfx::Size& sizeHint,
gfx::Border& borderHint,
gfx::Rect& textHint, int& textAlign);
static ui::Style m_defaultStyle;
};
} // namespace ui

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2018-2023 Igara Studio S.A.
// Copyright (C) 2018-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -199,7 +199,9 @@ void Widget::setTheme(Theme* theme)
void Widget::setStyle(Style* style)
{
assert_ui_thread();
ASSERT(style);
if (!style)
style = Theme::getDefaultStyle();
m_style = style;
m_border = m_theme->calcBorder(this, style);
m_bgColor = m_theme->calcBgColor(this, style);