mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-06 07:11:10 +00:00
fix: Compare Presets crash on filaments with different variant counts (#16176)
This commit is contained in:
@@ -53,6 +53,8 @@ wxString get_string_from_enum(const std::string& opt_key, const DynamicPrintConf
|
||||
}
|
||||
return _L("Undefined");
|
||||
}
|
||||
if (val < 0 || val >= int(names.size()))
|
||||
return _L("Undefined");
|
||||
return from_u8(_utf8(names[val]));
|
||||
}
|
||||
|
||||
@@ -215,6 +217,8 @@ wxString get_string_value(const std::string& opt_key, const DynamicPrintConfig&
|
||||
;
|
||||
}
|
||||
case coEnums: {
|
||||
if (!opt_vector || opt_idx >= opt_vector->size())
|
||||
return _L("Undefined");
|
||||
return get_string_from_enum(pure_key, config,
|
||||
pure_key == "top_surface_pattern" ||
|
||||
pure_key == "bottom_surface_pattern" ||
|
||||
|
||||
@@ -2,6 +2,7 @@ get_filename_component(_TEST_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
|
||||
add_executable(${_TEST_NAME}_tests
|
||||
${_TEST_NAME}_tests_main.cpp
|
||||
test_bambu_filament_ids.cpp
|
||||
test_config_value_formatter.cpp
|
||||
test_creality_cfs_match.cpp
|
||||
test_dev_mapping.cpp
|
||||
test_filament_bitmap_utils.cpp
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "libslic3r/PrintConfig.hpp"
|
||||
#include "slic3r/GUI/ConfigValueFormatter.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
using namespace Slic3r::GUI;
|
||||
|
||||
TEST_CASE("An enum vector index past the end of the vector reads as undefined", "[ConfigValueFormatter][Regression]")
|
||||
{
|
||||
const std::string key = "filament_retract_lift_enforce";
|
||||
const ConfigOptionDef* def = print_config_def.get(key);
|
||||
DynamicPrintConfig config;
|
||||
config.set_key_value(key, new ConfigOptionEnumsGenericNullable(def->enum_keys_map, 1, ConfigOptionEnumsGenericNullable::nil_value()));
|
||||
|
||||
CHECK(get_string_value(key + "#1", config) == "Undefined");
|
||||
}
|
||||
|
||||
TEST_CASE("An enum vector index inside the vector reads as its label", "[ConfigValueFormatter]")
|
||||
{
|
||||
const std::string key = "filament_retract_lift_enforce";
|
||||
const ConfigOptionDef* def = print_config_def.get(key);
|
||||
DynamicPrintConfig config;
|
||||
config.set_key_value(key, new ConfigOptionEnumsGenericNullable(def->enum_keys_map, 1, def->enum_keys_map->at("Top Only")));
|
||||
|
||||
CHECK(get_string_value(key + "#0", config).utf8_string() == "Top Only");
|
||||
}
|
||||
|
||||
TEST_CASE("An enum value outside the label list reads as undefined", "[ConfigValueFormatter]")
|
||||
{
|
||||
const std::string key = "filament_retract_lift_enforce";
|
||||
const ConfigOptionDef* def = print_config_def.get(key);
|
||||
DynamicPrintConfig config;
|
||||
config.set_key_value(key, new ConfigOptionEnumsGenericNullable(def->enum_keys_map, 1, int(def->enum_labels.size())));
|
||||
|
||||
CHECK(get_string_value(key + "#0", config) == "Undefined");
|
||||
}
|
||||
Reference in New Issue
Block a user