You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Fix editor crash when inspecting 2 objects handled by the same plugin
Already activated plugins do not need to be added again to `editor_plugins_over`. `fold_resource()` changes `active_plugins` and is unsafe to call while iterating over `active_plugins`.
This commit is contained in:
@@ -2397,22 +2397,39 @@ void EditorNode::edit_item(Object *p_object, Object *p_editing_owner) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool need_to_add = true;
|
||||||
|
List<EditorPropertyResource *> to_fold;
|
||||||
|
|
||||||
// If plugin is already associated with another owner, remove it from there first.
|
// If plugin is already associated with another owner, remove it from there first.
|
||||||
for (KeyValue<ObjectID, HashSet<EditorPlugin *>> &kv : active_plugins) {
|
for (KeyValue<ObjectID, HashSet<EditorPlugin *>> &kv : active_plugins) {
|
||||||
if (kv.key != owner_id) {
|
if (kv.key == owner_id || !kv.value.has(plugin)) {
|
||||||
EditorPropertyResource *epres = Object::cast_to<EditorPropertyResource>(ObjectDB::get_instance(kv.key));
|
continue;
|
||||||
if (epres && kv.value.has(plugin)) {
|
|
||||||
// If it's resource property editing the same resource type, fold it.
|
|
||||||
epres->fold_resource();
|
|
||||||
}
|
|
||||||
kv.value.erase(plugin);
|
|
||||||
}
|
}
|
||||||
|
EditorPropertyResource *epres = Object::cast_to<EditorPropertyResource>(ObjectDB::get_instance(kv.key));
|
||||||
|
if (epres) {
|
||||||
|
// If it's resource property editing the same resource type, fold it later to avoid premature modifications
|
||||||
|
// that may result in unsafe iteration of active_plugins.
|
||||||
|
to_fold.push_back(epres);
|
||||||
|
} else {
|
||||||
|
kv.value.erase(plugin);
|
||||||
|
need_to_add = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!need_to_add && to_fold.is_empty()) {
|
||||||
|
plugin->make_visible(true);
|
||||||
|
plugin->edit(p_object);
|
||||||
|
} else {
|
||||||
|
for (EditorPropertyResource *epres : to_fold) {
|
||||||
|
epres->fold_resource();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Call the function directly once a proper priority system is implemented.
|
||||||
|
to_over_edit.push_back(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activate previously inactive plugin and edit the object.
|
// Activate previously inactive plugin and edit the object.
|
||||||
active_plugins[owner_id].insert(plugin);
|
active_plugins[owner_id].insert(plugin);
|
||||||
// TODO: Call the function directly once a proper priority system is implemented.
|
|
||||||
to_over_edit.push_back(plugin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (EditorPlugin *plugin : to_over_edit) {
|
for (EditorPlugin *plugin : to_over_edit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user