소스 검색

Merge pull request #107632 from gongpha/potentially-memory-leak

Free nodes from instantiating if it is not a `Control` in the theme editor
Thaddeus Crews 2 달 전
부모
커밋
3f99c09685
1개의 변경된 파일8개의 추가작업 그리고 1개의 파일을 삭제
  1. 8 1
      editor/plugins/theme_editor_preview.cpp

+ 8 - 1
editor/plugins/theme_editor_preview.cpp

@@ -510,8 +510,15 @@ bool SceneThemeEditorPreview::set_preview_scene(const String &p_path) {
 	}
 
 	Node *instance = loaded_scene->instantiate();
-	if (!instance || !Object::cast_to<Control>(instance)) {
+
+	if (!instance) {
+		EditorNode::get_singleton()->show_warning(TTR("Invalid PackedScene resource, could not instantiate it."));
+		return false;
+	}
+
+	if (!Object::cast_to<Control>(instance)) {
 		EditorNode::get_singleton()->show_warning(TTR("Invalid PackedScene resource, must have a Control node at its root."));
+		memdelete(instance);
 		return false;
 	}