Skip to content

Commit

Permalink
Merge pull request #90265 from ajreckof/Fix-crash-on-invalid-values-i…
Browse files Browse the repository at this point in the history
…n-EditorPropertyArray/Dict

Fix crash on invalid values in EditorPropertyArray/Dict
  • Loading branch information
akien-mga committed Apr 5, 2024
2 parents a8e7688 + 866452c commit c493217
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions editor/editor_properties_array_dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ void EditorPropertyArray::update_property() {
memdelete(container);
button_add_item = nullptr;
container = nullptr;
slots.clear();
}
return;
}
Expand Down Expand Up @@ -586,7 +587,7 @@ void EditorPropertyArray::_edit_pressed() {
Variant array = get_edited_property_value();
if (!array.is_array() && edit->is_pressed()) {
initialize_array(array);
get_edited_object()->set(get_edited_property(), array);
emit_changed(get_edited_property(), array);
}

get_edited_object()->editor_set_section_unfold(get_edited_property(), edit->is_pressed());
Expand Down Expand Up @@ -867,14 +868,15 @@ void EditorPropertyDictionary::setup(PropertyHint p_hint) {
void EditorPropertyDictionary::update_property() {
Variant updated_val = get_edited_property_value();

if (updated_val.get_type() == Variant::NIL) {
if (updated_val.get_type() != Variant::DICTIONARY) {
edit->set_text(TTR("Dictionary (Nil)")); // This provides symmetry with the array property.
edit->set_pressed(false);
if (container) {
set_bottom_editor(nullptr);
memdelete(container);
button_add_item = nullptr;
container = nullptr;
slots.clear();
}
return;
}
Expand Down Expand Up @@ -1021,7 +1023,7 @@ void EditorPropertyDictionary::_edit_pressed() {
Variant prop_val = get_edited_property_value();
if (prop_val.get_type() == Variant::NIL && edit->is_pressed()) {
VariantInternal::initialize(&prop_val, Variant::DICTIONARY);
get_edited_object()->set(get_edited_property(), prop_val);
emit_changed(get_edited_property(), prop_val);
}

get_edited_object()->editor_set_section_unfold(get_edited_property(), edit->is_pressed());
Expand Down

0 comments on commit c493217

Please sign in to comment.