From 492df37e5c13e49c19b955494f45464ef3d54006 Mon Sep 17 00:00:00 2001 From: sparkleHazard <51274635+sparkleHazard@users.noreply.github.com> Date: Thu, 16 Apr 2026 08:28:08 +0100 Subject: [PATCH] Fix segfault in CLI mode when extruder/filament options absent (P1S profiles) (#13193) Fix segfault in CLI mode when extruder/filament options absent When slicing via CLI (--slice) with a BBL printer profile such as the P1S, update_values_to_printer_extruders and update_values_to_printer_extruders_for_multiple_filaments dereference option pointers without checking for nullptr first, causing a SIGSEGV. Root cause: printer profiles that have different_extruder=true (e.g. P1S variants) trigger these code paths even in single-extruder CLI invocations where filament_map, extruder_type, and nozzle_volume_type options may not be present in the resolved config. Fix: add null guards before dereferencing option<> / dynamic_cast<> results, consistent with the pattern used in PR #12719. Log a warning and return early rather than crashing. Fixes CLI --slice segfault (exit 139) with P1S profiles. Related: #12426, #12719 --- src/libslic3r/PrintApply.cpp | 3 ++- src/libslic3r/PrintConfig.cpp | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/PrintApply.cpp b/src/libslic3r/PrintApply.cpp index d2a44463ea..ac2d56780f 100644 --- a/src/libslic3r/PrintApply.cpp +++ b/src/libslic3r/PrintApply.cpp @@ -1163,7 +1163,8 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ m_ori_full_print_config = new_full_config; new_full_config.update_values_to_printer_extruders_for_multiple_filaments(new_full_config, filament_options_with_variant, "filament_self_index", "filament_extruder_variant"); - std::vector filament_maps = new_full_config.option("filament_map")->values; + auto opt_filament_map = new_full_config.option("filament_map"); + std::vector filament_maps = opt_filament_map ? opt_filament_map->values : std::vector(); // Find modified keys of the various configs. Resolve overrides extruder retract values by filament profiles. DynamicPrintConfig filament_overrides; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index d4711a0da9..daabe9e5ad 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -9007,6 +9007,10 @@ void DynamicPrintConfig::update_values_to_printer_extruders(DynamicPrintConfig& //int extruder_count = opt_nozzle_diameters->size(); auto opt_extruder_type = dynamic_cast(printer_config.option("extruder_type")); auto opt_nozzle_volume_type = dynamic_cast(printer_config.option("nozzle_volume_type")); + if (!opt_extruder_type || !opt_nozzle_volume_type) { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: extruder_type or nozzle_volume_type option not found, skipping")%__LINE__; + return; + } std::vector variant_index; if (extruder_id > 0 && extruder_id <= static_cast (extruder_count)) { @@ -9169,13 +9173,22 @@ void DynamicPrintConfig::update_values_to_printer_extruders_for_multiple_filamen if ((extruder_count > 1) || different_extruder) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: extruder_count=%2%, different_extruder=%3%")%__LINE__ %extruder_count %different_extruder; - std::vector filament_maps = printer_config.option("filament_map")->values; + auto opt_filament_map = printer_config.option("filament_map"); + if (!opt_filament_map) { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: filament_map option not found, skipping")%__LINE__; + return; + } + std::vector filament_maps = opt_filament_map->values; size_t filament_count = filament_maps.size(); //apply process settings //auto opt_nozzle_diameters = this->option("nozzle_diameter"); //int extruder_count = opt_nozzle_diameters->size(); auto opt_extruder_type = dynamic_cast(printer_config.option("extruder_type")); auto opt_nozzle_volume_type = dynamic_cast(printer_config.option("nozzle_volume_type")); + if (!opt_extruder_type || !opt_nozzle_volume_type) { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: extruder_type or nozzle_volume_type option not found, skipping")%__LINE__; + return; + } auto opt_ids = id_name.empty()? nullptr: dynamic_cast(this->option(id_name)); std::vector variant_index;