From e33a73d66e0ba0d743bf7b4d9991c6f2a7b61efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 3 Feb 2022 11:57:32 +0100 Subject: [PATCH] EditorProperty: Fix range hint parsing with optional step This could lead to have a step of 0 when parsing e.g. "1,10,is_greater". (cherry picked from commit 80306cc88a8023c8ffda7576c3ba8007b278c743) --- editor/editor_properties.cpp | 39 +++++++++++++++++++++--------------- main/main.cpp | 8 ++++---- scene/main/scene_tree.cpp | 5 ++--- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index ccb05cb571e..9746a6c3170 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2616,18 +2616,20 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ int min = 0, max = 65535, step = 1; bool greater = true, lesser = true; - if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { - greater = false; //if using ranged, assume false by default + Vector slices = p_hint_text.split(","); + if (p_hint == PROPERTY_HINT_RANGE && slices.size() >= 2) { + greater = false; // If using ranged, assume false by default. lesser = false; - min = p_hint_text.get_slice(",", 0).to_int(); - max = p_hint_text.get_slice(",", 1).to_int(); + min = slices[0].to_int(); + max = slices[1].to_int(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_int(); + if (slices.size() >= 3 && slices[2].is_valid_integer()) { + // Step is optional, could be something else if not a number. + step = slices[2].to_int(); } - for (int i = 2; i < p_hint_text.get_slice_count(","); i++) { - String slice = p_hint_text.get_slice(",", i).strip_edges(); + for (int i = 2; i < slices.size(); i++) { + String slice = slices[i].strip_edges(); if (slice == "or_greater") { greater = true; } @@ -2668,18 +2670,23 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ bool exp_range = false; bool greater = true, lesser = true; - if ((p_hint == PROPERTY_HINT_RANGE || p_hint == PROPERTY_HINT_EXP_RANGE) && p_hint_text.get_slice_count(",") >= 2) { - greater = false; //if using ranged, assume false by default + Vector slices = p_hint_text.split(","); + if ((p_hint == PROPERTY_HINT_RANGE || p_hint == PROPERTY_HINT_EXP_RANGE) && slices.size() >= 2) { + greater = false; // If using ranged, assume false by default. lesser = false; - min = p_hint_text.get_slice(",", 0).to_double(); - max = p_hint_text.get_slice(",", 1).to_double(); - if (p_hint_text.get_slice_count(",") >= 3) { - step = p_hint_text.get_slice(",", 2).to_double(); + min = slices[0].to_double(); + max = slices[1].to_double(); + + if (slices.size() >= 3 && slices[2].is_valid_float()) { + // Step is optional, could be something else if not a number. + step = slices[2].to_double(); } + hide_slider = false; exp_range = p_hint == PROPERTY_HINT_EXP_RANGE; - for (int i = 2; i < p_hint_text.get_slice_count(","); i++) { - String slice = p_hint_text.get_slice(",", i).strip_edges(); + + for (int i = 2; i < slices.size(); i++) { + String slice = slices[i].strip_edges(); if (slice == "or_greater") { greater = true; } diff --git a/main/main.cpp b/main/main.cpp index 0fc950bf22c..95f8580982c 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1044,17 +1044,17 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph GLOBAL_DEF("rendering/2d/options/use_nvidia_rect_flicker_workaround", false); GLOBAL_DEF("display/window/size/width", 1024); - ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/width", PropertyInfo(Variant::INT, "display/window/size/width", PROPERTY_HINT_RANGE, "0,7680,or_greater")); // 8K resolution + ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/width", PropertyInfo(Variant::INT, "display/window/size/width", PROPERTY_HINT_RANGE, "0,7680,1,or_greater")); // 8K resolution GLOBAL_DEF("display/window/size/height", 600); - ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/height", PropertyInfo(Variant::INT, "display/window/size/height", PROPERTY_HINT_RANGE, "0,4320,or_greater")); // 8K resolution + ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/height", PropertyInfo(Variant::INT, "display/window/size/height", PROPERTY_HINT_RANGE, "0,4320,1,or_greater")); // 8K resolution GLOBAL_DEF("display/window/size/resizable", true); GLOBAL_DEF("display/window/size/borderless", false); GLOBAL_DEF("display/window/size/fullscreen", false); GLOBAL_DEF("display/window/size/always_on_top", false); GLOBAL_DEF("display/window/size/test_width", 0); - ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/test_width", PropertyInfo(Variant::INT, "display/window/size/test_width", PROPERTY_HINT_RANGE, "0,7680,or_greater")); // 8K resolution + ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/test_width", PropertyInfo(Variant::INT, "display/window/size/test_width", PROPERTY_HINT_RANGE, "0,7680,1,or_greater")); // 8K resolution GLOBAL_DEF("display/window/size/test_height", 0); - ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/test_height", PropertyInfo(Variant::INT, "display/window/size/test_height", PROPERTY_HINT_RANGE, "0,4320,or_greater")); // 8K resolution + ProjectSettings::get_singleton()->set_custom_property_info("display/window/size/test_height", PropertyInfo(Variant::INT, "display/window/size/test_height", PROPERTY_HINT_RANGE, "0,4320,1,or_greater")); // 8K resolution if (use_custom_res) { if (!force_res) { diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index d71160a7574..b3cce2f6a46 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -2055,15 +2055,14 @@ SceneTree::SceneTree() { multiplayer_poll = true; set_multiplayer(Ref(memnew(MultiplayerAPI))); - //root->set_world_2d( Ref( memnew( World2D ))); root->set_as_audio_listener(true); root->set_as_audio_listener_2d(true); current_scene = nullptr; int ref_atlas_size = GLOBAL_DEF_RST("rendering/quality/reflections/atlas_size", 2048); - ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/reflections/atlas_size", PropertyInfo(Variant::INT, "rendering/quality/reflections/atlas_size", PROPERTY_HINT_RANGE, "0,8192,or_greater")); //next_power_of_2 will return a 0 as min value + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/reflections/atlas_size", PropertyInfo(Variant::INT, "rendering/quality/reflections/atlas_size", PROPERTY_HINT_RANGE, "0,8192,1,or_greater")); // next_power_of_2 will return a 0 as min value. int ref_atlas_subdiv = GLOBAL_DEF_RST("rendering/quality/reflections/atlas_subdiv", 8); - ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/reflections/atlas_subdiv", PropertyInfo(Variant::INT, "rendering/quality/reflections/atlas_subdiv", PROPERTY_HINT_RANGE, "0,32,or_greater")); //next_power_of_2 will return a 0 as min value + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/reflections/atlas_subdiv", PropertyInfo(Variant::INT, "rendering/quality/reflections/atlas_subdiv", PROPERTY_HINT_RANGE, "0,32,1,or_greater")); // next_power_of_2 will return a 0 as min value. int msaa_mode = GLOBAL_DEF("rendering/quality/filters/msaa", 0); ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/filters/msaa", PropertyInfo(Variant::INT, "rendering/quality/filters/msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x")); root->set_msaa(Viewport::MSAA(msaa_mode));