From 56ec9f113cccd68e9227866ab2090841a4f7ebb8 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 25 Jun 2018 14:05:57 -0300 Subject: [PATCH] Avoid crash if the theme package doesn't contain a sheet.png file --- src/app/ui/skin/skin_theme.cpp | 5 ++++- src/she/skia/skia_surface.cpp | 8 ++++++-- src/ui/theme.cpp | 7 +------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/app/ui/skin/skin_theme.cpp b/src/app/ui/skin/skin_theme.cpp index d63752ac7..a462dcc31 100644 --- a/src/app/ui/skin/skin_theme.cpp +++ b/src/app/ui/skin/skin_theme.cpp @@ -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) { diff --git a/src/she/skia/skia_surface.cpp b/src/she/skia/skia_surface.cpp index 679c712e9..4597b06e8 100644 --- a/src/she/skia/skia_surface.cpp +++ b/src/she/skia/skia_surface.cpp @@ -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 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 codec( SkCodec::MakeFromStream( - std::unique_ptr(new SkFILEStream(base::open_file_raw(filename, "rb"))))); + std::unique_ptr(new SkFILEStream(f)))); if (!codec) return nullptr; diff --git a/src/ui/theme.cpp b/src/ui/theme.cpp index 4d210e4a9..d71e72ac4 100644 --- a/src/ui/theme.cpp +++ b/src/ui/theme.cpp @@ -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;