Skip to content

Commit 411f476

Browse files
committed
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`.
1 parent 28102e6 commit 411f476

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

editor/editor_node.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,22 +2397,39 @@ void EditorNode::edit_item(Object *p_object, Object *p_editing_owner) {
23972397
continue;
23982398
}
23992399

2400+
bool need_to_add = true;
2401+
List<EditorPropertyResource *> to_fold;
2402+
24002403
// If plugin is already associated with another owner, remove it from there first.
24012404
for (KeyValue<ObjectID, HashSet<EditorPlugin *>> &kv : active_plugins) {
2402-
if (kv.key != owner_id) {
2403-
EditorPropertyResource *epres = Object::cast_to<EditorPropertyResource>(ObjectDB::get_instance(kv.key));
2404-
if (epres && kv.value.has(plugin)) {
2405-
// If it's resource property editing the same resource type, fold it.
2406-
epres->fold_resource();
2407-
}
2405+
if (kv.key == owner_id || !kv.value.has(plugin)) {
2406+
continue;
2407+
}
2408+
EditorPropertyResource *epres = Object::cast_to<EditorPropertyResource>(ObjectDB::get_instance(kv.key));
2409+
if (epres) {
2410+
// If it's resource property editing the same resource type, fold it later to avoid premature modifications
2411+
// that may result in unsafe iteration of active_plugins.
2412+
to_fold.push_back(epres);
2413+
} else {
24082414
kv.value.erase(plugin);
2415+
need_to_add = false;
2416+
}
2417+
}
2418+
2419+
if (!need_to_add && to_fold.is_empty()) {
2420+
plugin->make_visible(true);
2421+
plugin->edit(p_object);
2422+
} else {
2423+
for (EditorPropertyResource *epres : to_fold) {
2424+
epres->fold_resource();
24092425
}
2426+
2427+
// TODO: Call the function directly once a proper priority system is implemented.
2428+
to_over_edit.push_back(plugin);
24102429
}
24112430

24122431
// Activate previously inactive plugin and edit the object.
24132432
active_plugins[owner_id].insert(plugin);
2414-
// TODO: Call the function directly once a proper priority system is implemented.
2415-
to_over_edit.push_back(plugin);
24162433
}
24172434

24182435
for (EditorPlugin *plugin : to_over_edit) {

0 commit comments

Comments
 (0)