diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 8320559942..ffd5c2f6e1 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -145,6 +145,9 @@ Semver get_version_from_json(std::string file_path) return Semver(); //throw ConfigurationError(format("Failed loading configuration file \"%1%\": %2%", file_path, err.what())); } + catch(...) { + return Semver(); + } } //BBS: add a function to load the key-values from xxx.json diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 1665fbcb17..8ea83314d7 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -2202,7 +2202,7 @@ std::pair PresetBundle::load_system_pre const auto t0 = std::chrono::steady_clock::now(); PresetBundleCache::SystemPresetsCache cache; const std::string cache_file = PresetBundleCache::SystemPresetsCache::cache_path(); - if (cache.load(cache_file)) { + if (cache.load(cache_file) && cache.is_plausible()) { std::set dirty; if (cache.get_dirty_vendors(dir.string(), dirty)) { if (dirty.empty()) { @@ -2230,7 +2230,7 @@ std::pair PresetBundle::load_system_pre (boost::filesystem::path(resources_dir()) / "profiles").make_preferred().string(); PresetBundleCache::SystemPresetsCache bundled; if (bundled.load(PresetBundleCache::SystemPresetsCache::bundled_cache_path()) && - bundled.is_valid(bundled_dir)) { + bundled.is_valid(bundled_dir) && bundled.is_plausible()) { bundled.apply(*this); update_system_maps(); // Promote to user cache so subsequent launches skip this check. diff --git a/src/libslic3r/PresetBundleCache.hpp b/src/libslic3r/PresetBundleCache.hpp index 6996357b71..b2ddbc31b6 100644 --- a/src/libslic3r/PresetBundleCache.hpp +++ b/src/libslic3r/PresetBundleCache.hpp @@ -122,6 +122,13 @@ struct SystemPresetsCache { static std::string cache_path(); static std::string bundled_cache_path(); bool is_valid(const std::string& system_dir) const; + // Rejects caches that loaded structurally but contain no data or are internally inconsistent + // (e.g. vendor_versions lists all vendors but vendor_profiles only captured some of them). + bool is_plausible() const { + return !vendor_profiles.empty() && + !printer_presets.empty() && + vendor_versions.size() == vendor_profiles.size(); + } // Returns false on structural mismatch (full re-parse required). // On true, populates out_dirty with vendor IDs whose version strings changed. // Empty out_dirty means fully valid (cache hit, no re-parse needed).