Avoid crash if the theme package doesn't contain a sheet.png file

This commit is contained in:
David Capello 2018-06-25 14:05:57 -03:00
parent 58b9dfed11
commit 56ec9f113c
3 changed files with 11 additions and 9 deletions

View File

@ -287,8 +287,11 @@ void SkinTheme::loadSheet()
newSheet = she::instance()->loadRgbaSurface(sheet_filename.c_str());
}
catch (...) {
throw base::Exception("Error loading %s file", sheet_filename.c_str());
// Ignore the error, newSheet is nullptr and we will throw our own
// exception.
}
if (!newSheet)
throw base::Exception("Error loading %s file", sheet_filename.c_str());
// Replace the sprite sheet
if (m_sheet) {

View File

@ -1,5 +1,5 @@
// SHE library
// Copyright (C) 2016 David Capello
// Copyright (C) 2016-2018 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -25,9 +25,13 @@ sk_sp<SkColorSpace> SkiaSurface::m_colorSpace;
// static
Surface* SkiaSurface::loadSurface(const char* filename)
{
FILE* f = base::open_file_raw(filename, "rb");
if (!f)
return nullptr;
std::unique_ptr<SkCodec> codec(
SkCodec::MakeFromStream(
std::unique_ptr<SkFILEStream>(new SkFILEStream(base::open_file_raw(filename, "rb")))));
std::unique_ptr<SkFILEStream>(new SkFILEStream(f))));
if (!codec)
return nullptr;

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2001-2017 David Capello
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -654,11 +654,6 @@ void set_theme(Theme* theme, const int uiscale)
current_ui_scale = uiscale;
if (theme) {
// As the regeneration may fail, first we regenerate the theme and
// then we set is as "the current theme." E.g. In case that we'd
// like to show some kind of error message with the UI controls,
// we should be able to use the previous theme to do so (instead
// of this new unsuccessfully regenerated theme).
theme->regenerateTheme();
current_theme = theme;