Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on invalid values in EditorPropertyArray/Dict #90265

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part missing was the one creating the crash

}
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);
Comment on lines -589 to +590
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would have caused problem on nested arrays

}

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) {
Comment on lines -870 to +871
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to not only check for null but for anything that wouldn't be treated well (only dictionary is expected) just as EditorPropertyArray checks with is_array.

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
Loading