Skip to content

Commit 3f99c09

Browse files
committed
Merge pull request #107632 from gongpha/potentially-memory-leak
Free nodes from instantiating if it is not a `Control` in the theme editor
2 parents b0dc2b4 + 4067d7d commit 3f99c09

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

editor/plugins/theme_editor_preview.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,15 @@ bool SceneThemeEditorPreview::set_preview_scene(const String &p_path) {
510510
}
511511

512512
Node *instance = loaded_scene->instantiate();
513-
if (!instance || !Object::cast_to<Control>(instance)) {
513+
514+
if (!instance) {
515+
EditorNode::get_singleton()->show_warning(TTR("Invalid PackedScene resource, could not instantiate it."));
516+
return false;
517+
}
518+
519+
if (!Object::cast_to<Control>(instance)) {
514520
EditorNode::get_singleton()->show_warning(TTR("Invalid PackedScene resource, must have a Control node at its root."));
521+
memdelete(instance);
515522
return false;
516523
}
517524

0 commit comments

Comments
 (0)