mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
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:
parent
078dac28d7
commit
f22603caea
@ -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 {
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user