From eda4062d68abe3b68155bb06270906dbbfb70ae2 Mon Sep 17 00:00:00 2001 From: Kris Austin Date: Fri, 30 Oct 2026 12:45:47 -0500 Subject: [PATCH] Fix crash opening a project with missing or empty settings (#17040) fix: crash opening a project with missing or empty settings load_files reads filament_colour from the project config before the defaults are merged in, and uses it without a null check. A 3MF whose project_settings.config has no filament_colour crashes on open. The 2.3.1-alpha migration reads sparse_infill_rotate_template and sparse_infill_pattern the same way. Check those reads for null. A missing filament_colour keeps the count at 1, and a missing infill pattern falls back to the default the merge would apply. The two identical 2.3.1-alpha migrations become one lambda. The 2.3.1-alpha and newer-version branches also skipped the empty-config check, so an empty project config reached the same reads. Send every project config the load skips through one fallback that loads the geometry only and logs it. It keeps each branch's notice, and a config-only import now says the 3MF has no project settings OrcaSlicer can import instead of claiming to load geometry. A same-version file no longer calls itself old. Geometry-only imports decided by these checks never added filaments for objects assigned past the first, because that step ran before them. Run it after the checks. Count project filaments per file, and drop the two branches at the end of the chain that no file type reaches. Fixes #17008 --- src/slic3r/GUI/Plater.cpp | 292 +++++++++++++++++--------------------- 1 file changed, 127 insertions(+), 165 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index db0f4da94d..e051dca705 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -8970,7 +8970,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ bool dlg_cont = true; bool is_user_cancel = false; bool translate_old = false; - int current_width = 0, current_depth = 0, project_filament_count = 1; + int current_width = 0, current_depth = 0; double current_height = 0; if (input_files.empty()) @@ -9051,6 +9051,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ const float LOAD_MODEL_RATIO = 0.9; for (size_t i = 0; i < input_files.size(); ++i) { + int project_filament_count = 1; #ifdef _WIN32 auto path = input_files[i]; @@ -9240,8 +9241,130 @@ std::vector Plater::priv::load_files(const std::vector& input_ } } + std::string import_project_action = wxGetApp().app_config->get("import_project_action"); + LoadType load_type; + if (import_project_action.empty()) + load_type = LoadType::Unknown; + else + load_type = static_cast(std::stoi(import_project_action)); + + // BBS: version check + Semver app_version = *(Semver::parse(SoftFever_VERSION)); + const wxString load_3mf_title = _L("Load 3MF"); + const wxString newer_3mf_title = _L("Newer 3MF version"); + const wxString msg_unsupported_geometry = _L("The 3MF is not supported by OrcaSlicer, loading geometry data only."); + const wxString msg_old_orca_geometry = _L("The 3MF file was generated by an old OrcaSlicer version, loading geometry data only."); + const wxString msg_older_geometry = _L("The 3MF file was generated by an older version, loading geometry data only."); + const wxString msg_bambu_geometry = _L("The 3MF file was generated by BambuStudio, loading geometry data only."); + const wxString msg_no_project_settings = _L("The 3MF file has no project settings that OrcaSlicer can import."); + auto log_and_show_3mf_info = [&](const wxString& text, const wxString& title) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ + << " " + << boost::format("3MF import message [%1%]: %2% | file: %3%") % into_u8(title) % into_u8(text) % path.string(); + show_info(q, text, title); + }; + auto skip_project_config = [&](const wxString& geometry_msg) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ + << boost::format(" 3MF project config not loaded, importing geometry only: %1%") % path.string(); + load_config = false; + if (!load_model) + log_and_show_3mf_info(msg_no_project_settings, load_3mf_title); + else if (!geometry_msg.empty()) + log_and_show_3mf_info(geometry_msg, load_3mf_title); + }; + auto migrate_2_3_1_alpha_rotate_template = [&]() { + auto* rotate_template = config_loaded.option("sparse_infill_rotate_template"); + if (rotate_template == nullptr || rotate_template->value.empty()) + return; + const auto* pattern_opt = config_loaded.option>("sparse_infill_pattern"); + const auto _sparse_infill_pattern = + pattern_opt != nullptr ? pattern_opt->value : FullPrintConfig::defaults().sparse_infill_pattern.value; + bool is_safe_to_rotate = _sparse_infill_pattern == ipRectilinear || _sparse_infill_pattern == ipLine || + _sparse_infill_pattern == ipZigZag || _sparse_infill_pattern == ipCrossZag || + _sparse_infill_pattern == ipLockedZag; + if (!is_safe_to_rotate) { + wxString msg_text = _( + L("This project was created with an OrcaSlicer 2.3.1-alpha and uses " + "infill rotation template settings that may not work properly with your current infill pattern. " + "This could result in weak support or print quality issues.")); + msg_text += "\n\n" + + _(L("Would you like OrcaSlicer to automatically fix this by clearing the rotation template settings?")); + MessageDialog dialog(wxGetApp().plater(), msg_text, "", wxICON_WARNING | wxYES | wxNO); + dialog.SetButtonLabel(wxID_YES, _L("Yes")); + dialog.SetButtonLabel(wxID_NO, _L("No")); + if (dialog.ShowModal() == wxID_YES) { + rotate_template->value.clear(); + } + } + }; + // Untagged files up to 2.3.2 may also come from OrcaSlicer, which only started tagging its 3MFs after it. + const bool is_bambu_studio_project = en_3mf_file_type == En3mfType::From_BBS && file_version > Semver(2, 3, 2); + if (en_3mf_file_type == En3mfType::From_Prusa) { + // do not reset the model config + skip_project_config(load_type != LoadType::LoadGeometry ? msg_unsupported_geometry : wxString()); + } + else if (en_3mf_file_type == En3mfType::From_Orca) { + // OrcaSlicer file (has OrcaSlicer tag) - compare file_version with SoftFever_VERSION + if (load_config && !config_loaded.empty() && (file_version < app_version) && file_version == Semver("2.3.1-alpha")) { + migrate_2_3_1_alpha_rotate_template(); + } else if (load_config && (file_version > app_version)) { + if (config_substitutions.unrecogized_keys.size() > 0) { + wxString text = wxString::Format(_L("The 3MF file version %s is newer than %s's version %s, found the following unrecognized keys:"), + file_version.to_string_sf(), std::string(SLIC3R_APP_FULL_NAME), app_version.to_string_sf()); + text += "\n" + from_u8(boost::algorithm::join(config_substitutions.unrecogized_keys, ", ")) + "\n\n"; + text += _L("You should update your software.\n"); + log_and_show_3mf_info(text, newer_3mf_title); + } + else { + //if the minor version is not matched + if (file_version.min() != app_version.min()) { + wxString text = wxString::Format(_L("The 3MF file version %s is newer than %s's version %s, we suggest to upgrade your software."), + file_version.to_string_sf(), std::string(SLIC3R_APP_FULL_NAME), app_version.to_string_sf()); + text += "\n"; + log_and_show_3mf_info(text, newer_3mf_title); + } + } + if (config_loaded.empty()) + skip_project_config(wxString()); + } + else if (load_config && config_loaded.empty()) { + skip_project_config(file_version < app_version ? msg_old_orca_geometry : wxString()); + } + } + else if (en_3mf_file_type == En3mfType::From_BBS) { + // No OrcaSlicer tag - check Bambu/Application version + if (!is_bambu_studio_project) { + // Compatible old version (before OrcaSlicer tagging was introduced after 2.3.2). + // Any version prior or equal to 2.3.2 is older than the current one, no version warnings needed. + // Still apply migration fixes for known old versions. + if (load_config && !config_loaded.empty() && (file_version == Semver("2.3.1-alpha"))) { + migrate_2_3_1_alpha_rotate_template(); + } + else if (load_config && config_loaded.empty()) { + skip_project_config(msg_older_geometry); + } + } else { + // BambuStudio project (version > 2.3.2 without OrcaSlicer tag) + if (load_config && config_loaded.empty()) { + skip_project_config(msg_bambu_geometry); + } + else if (load_config) { + // Logged, not shown: it is the same for every BambuStudio project and needs no action. + const std::string unrecognized = boost::algorithm::join(config_substitutions.unrecogized_keys, ", "); + BOOST_LOG_TRIVIAL(info) << "BambuStudio " << file_version.to_string() << " project " << path.string() + << ", unrecognized settings: " << (unrecognized.empty() ? "none" : unrecognized); + } + } + } + else if (en_3mf_file_type == En3mfType::From_Other) { + // Generic CAD/other 3MF without slicer metadata: import geometry silently. + if (load_config && config_loaded.empty()) { + skip_project_config(wxString()); + } + } + // 1. add extruder for prusa model if the number of existing extruders is not enough - // 2. add extruder for BBS or Other model if only import geometry + // 2. add extruder for BBS or Other model if only import geometry, by choice or by the checks above if (en_3mf_file_type == En3mfType::From_Prusa || (load_model && !load_config)) { std::set extruderIds; for (ModelObject *o : model.objects) { @@ -9265,168 +9388,6 @@ std::vector Plater::priv::load_files(const std::vector& input_ wxGetApp().get_tab(Preset::TYPE_PRINT)->update(); } - std::string import_project_action = wxGetApp().app_config->get("import_project_action"); - LoadType load_type; - if (import_project_action.empty()) - load_type = LoadType::Unknown; - else - load_type = static_cast(std::stoi(import_project_action)); - - // BBS: version check - Semver app_version = *(Semver::parse(SoftFever_VERSION)); - const wxString load_3mf_title = _L("Load 3MF"); - const wxString newer_3mf_title = _L("Newer 3MF version"); - const wxString msg_unsupported_geometry = _L("The 3MF is not supported by OrcaSlicer, loading geometry data only."); - const wxString msg_old_orca_geometry = _L("The 3MF file was generated by an old OrcaSlicer version, loading geometry data only."); - const wxString msg_older_geometry = _L("The 3MF file was generated by an older version, loading geometry data only."); - const wxString msg_bambu_geometry = _L("The 3MF file was generated by BambuStudio, loading geometry data only."); - auto log_and_show_3mf_info = [&](const wxString& text, const wxString& title) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ - << " " - << boost::format("3MF import message [%1%]: %2% | file: %3%") % into_u8(title) % into_u8(text) % path.string(); - show_info(q, text, title); - }; - // Untagged files up to 2.3.2 may also come from OrcaSlicer, which only started tagging its 3MFs after it. - const bool is_bambu_studio_project = en_3mf_file_type == En3mfType::From_BBS && file_version > Semver(2, 3, 2); - if (en_3mf_file_type == En3mfType::From_Prusa) { - // do not reset the model config - load_config = false; - if (load_type != LoadType::LoadGeometry) - log_and_show_3mf_info(msg_unsupported_geometry, load_3mf_title); - } - else if (en_3mf_file_type == En3mfType::From_Orca) { - // OrcaSlicer file (has OrcaSlicer tag) - compare file_version with SoftFever_VERSION - // Migration fix for OrcaSlicer 2.3.1-alpha sparse infill rotation template - if (load_config && (file_version < app_version) && file_version == Semver("2.3.1-alpha")) { - if (!config_loaded.opt_string("sparse_infill_rotate_template").empty()) { - const auto _sparse_infill_pattern = - config_loaded.option>("sparse_infill_pattern")->value; - bool is_safe_to_rotate = _sparse_infill_pattern == ipRectilinear || _sparse_infill_pattern == ipLine || - _sparse_infill_pattern == ipZigZag || _sparse_infill_pattern == ipCrossZag || - _sparse_infill_pattern == ipLockedZag; - if (!is_safe_to_rotate) { - wxString msg_text = _( - L("This project was created with an OrcaSlicer 2.3.1-alpha and uses " - "infill rotation template settings that may not work properly with your current infill pattern. " - "This could result in weak support or print quality issues.")); - msg_text += "\n\n" + - _(L("Would you like OrcaSlicer to automatically fix this by clearing the rotation template settings?")); - MessageDialog dialog(wxGetApp().plater(), msg_text, "", wxICON_WARNING | wxYES | wxNO); - dialog.SetButtonLabel(wxID_YES, _L("Yes")); - dialog.SetButtonLabel(wxID_NO, _L("No")); - if (dialog.ShowModal() == wxID_YES) { - config_loaded.opt_string("sparse_infill_rotate_template") = ""; - } - } - } - } else if (load_config && (file_version > app_version)) { - if (config_substitutions.unrecogized_keys.size() > 0) { - wxString text = wxString::Format(_L("The 3MF file version %s is newer than %s's version %s, found the following unrecognized keys:"), - file_version.to_string_sf(), std::string(SLIC3R_APP_FULL_NAME), app_version.to_string_sf()); - text += "\n" + from_u8(boost::algorithm::join(config_substitutions.unrecogized_keys, ", ")) + "\n\n"; - text += _L("You should update your software.\n"); - log_and_show_3mf_info(text, newer_3mf_title); - } - else { - //if the minor version is not matched - if (file_version.min() != app_version.min()) { - wxString text = wxString::Format(_L("The 3MF file version %s is newer than %s's version %s, we suggest to upgrade your software."), - file_version.to_string_sf(), std::string(SLIC3R_APP_FULL_NAME), app_version.to_string_sf()); - text += "\n"; - log_and_show_3mf_info(text, newer_3mf_title); - } - } - } - else if (load_config && config_loaded.empty()) { - load_config = false; - log_and_show_3mf_info(msg_old_orca_geometry, load_3mf_title); - } - } - else if (en_3mf_file_type == En3mfType::From_BBS) { - // No OrcaSlicer tag - check Bambu/Application version - if (!is_bambu_studio_project) { - // Compatible old version (before OrcaSlicer tagging was introduced after 2.3.2). - // Any version prior or equal to 2.3.2 is older than the current one, no version warnings needed. - // Still apply migration fixes for known old versions. - if (load_config && (file_version == Semver("2.3.1-alpha"))) { - if (!config_loaded.opt_string("sparse_infill_rotate_template").empty()) { - const auto _sparse_infill_pattern = - config_loaded.option>("sparse_infill_pattern")->value; - bool is_safe_to_rotate = _sparse_infill_pattern == ipRectilinear || _sparse_infill_pattern == ipLine || - _sparse_infill_pattern == ipZigZag || _sparse_infill_pattern == ipCrossZag || - _sparse_infill_pattern == ipLockedZag; - if (!is_safe_to_rotate) { - wxString msg_text = _( - L("This project was created with an OrcaSlicer 2.3.1-alpha and uses " - "infill rotation template settings that may not work properly with your current infill pattern. " - "This could result in weak support or print quality issues.")); - msg_text += "\n\n" + - _(L("Would you like OrcaSlicer to automatically fix this by clearing the rotation template settings?")); - MessageDialog dialog(wxGetApp().plater(), msg_text, "", wxICON_WARNING | wxYES | wxNO); - dialog.SetButtonLabel(wxID_YES, _L("Yes")); - dialog.SetButtonLabel(wxID_NO, _L("No")); - if (dialog.ShowModal() == wxID_YES) { - config_loaded.opt_string("sparse_infill_rotate_template") = ""; - } - } - } - } - else if (load_config && config_loaded.empty()) { - load_config = false; - log_and_show_3mf_info(msg_older_geometry, load_3mf_title); - } - } else { - // BambuStudio project (version > 2.3.2 without OrcaSlicer tag) - if (load_config && config_loaded.empty()) { - load_config = false; - log_and_show_3mf_info(msg_bambu_geometry, load_3mf_title); - } - else if (load_config) { - // Logged, not shown: it is the same for every BambuStudio project and needs no action. - const std::string unrecognized = boost::algorithm::join(config_substitutions.unrecogized_keys, ", "); - BOOST_LOG_TRIVIAL(info) << "BambuStudio " << file_version.to_string() << " project " << path.string() - << ", unrecognized settings: " << (unrecognized.empty() ? "none" : unrecognized); - } - } - } - else if (en_3mf_file_type == En3mfType::From_Other) { - // Generic CAD/other 3MF without slicer metadata: import geometry silently. - if (load_config && config_loaded.empty()) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ - << " " - << boost::format("3MF has no slicer metadata/project config, importing geometry only: %1%") % path.string(); - load_config = false; - } - } - else if (load_config && config_loaded.empty()) { - load_config = false; - log_and_show_3mf_info(msg_old_orca_geometry, load_3mf_title); - } - else if (!load_config) { - // reset config except color - for (ModelObject *model_object : model.objects) { - bool has_extruder = model_object->config.has("extruder"); - int extruder_id = -1; - // save the extruder information before reset - if (has_extruder) { extruder_id = model_object->config.extruder(); } - - model_object->config.reset(); - - // restore the extruder after reset - if (has_extruder) { model_object->config.set("extruder", extruder_id); } - - // Is there any modifier or advanced config data? - for (ModelVolume *model_volume : model_object->volumes) { - has_extruder = model_volume->config.has("extruder"); - if (has_extruder) { extruder_id = model_volume->config.extruder(); } - - model_volume->config.reset(); - - if (has_extruder) { model_volume->config.set("extruder", extruder_id); } - } - } - } - // ORCA: legacy feature-filament default migration (1 -> 0) is now handled // uniformly in PrintConfigDef::handle_legacy() via the old->new key rename // (wall_filament -> wall_filament_id, etc.), which also covers saved presets. @@ -9454,7 +9415,8 @@ std::vector Plater::priv::load_files(const std::vector& input_ //set the size back partplate_list.reset_size(current_width + Bed3D::Axes::DefaultTipRadius, current_depth + Bed3D::Axes::DefaultTipRadius, current_height, false); } - project_filament_count = config_loaded.option("filament_colour")->size(); + if (const auto* colours_opt = config_loaded.option("filament_colour")) + project_filament_count = colours_opt->size(); partplate_list.load_from_3mf_structure(plate_data, project_filament_count); partplate_list.update_slice_context_to_current_plate(background_process); this->preview->update_gcode_result(partplate_list.get_current_slice_result());