From 0220ae4ce530bc455f139e5cf4d197db19ba22e0 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 15 Jul 2021 09:04:12 +0200 Subject: [PATCH] Fixed a crash when "resources/shapes" directory doesn't exist. + Localization for the "Internal error: %1%" in generic_exception_handle() --- src/slic3r/GUI/GUI_App.cpp | 2 +- src/slic3r/GUI/GalleryDialog.cpp | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 2c4d07a66..d5740ddaa 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -608,7 +608,7 @@ static void generic_exception_handle() std::terminate(); throw; } catch (const std::exception& ex) { - wxLogError("Internal error: %s", wxString::FromUTF8(ex.what())); + wxLogError(format_wxstr(_L("Internal error: %1%"), ex.what())); BOOST_LOG_TRIVIAL(error) << boost::format("Uncaught exception: %1%") % ex.what(); throw; } diff --git a/src/slic3r/GUI/GalleryDialog.cpp b/src/slic3r/GUI/GalleryDialog.cpp index adc21ed0b..d124eda69 100644 --- a/src/slic3r/GUI/GalleryDialog.cpp +++ b/src/slic3r/GUI/GalleryDialog.cpp @@ -219,11 +219,6 @@ static fs::path get_dir(bool sys_dir) return fs::absolute(fs::path(data_dir()) / "shapes").make_preferred(); } -static bool custom_exists() -{ - return fs::exists(get_dir(false)); -} - static std::string get_dir_path(bool sys_dir) { fs::path dir = get_dir(sys_dir); @@ -299,6 +294,9 @@ void GalleryDialog::load_label_icon_list() auto add_files_from_gallery = [](std::vector& items, bool sys_dir, std::string& dir_path) { fs::path dir = get_dir(sys_dir); + if (!fs::exists(dir)) + return; + dir_path = get_dir_path(sys_dir); std::vector sorted_names; @@ -319,8 +317,7 @@ void GalleryDialog::load_label_icon_list() std::string m_sys_dir_path, m_cust_dir_path; std::vector list_items; add_files_from_gallery(list_items, true, m_sys_dir_path); - if (custom_exists()) - add_files_from_gallery(list_items, false, m_cust_dir_path); + add_files_from_gallery(list_items, false, m_cust_dir_path); // Make an image list containing large icons