瀏覽代碼

Prevent crash when dropping Resource that can't load

kobewi 1 年之前
父節點
當前提交
64eff14a46
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      editor/plugins/script_text_editor.cpp

+ 5 - 0
editor/plugins/script_text_editor.cpp

@@ -1838,6 +1838,11 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
 
 			if (drop_modifier_pressed && ResourceLoader::exists(path)) {
 				Ref<Resource> resource = ResourceLoader::load(path);
+				if (resource.is_null()) {
+					// Resource exists, but failed to load. We need only path and name, so we can use a dummy Resource instead.
+					resource.instantiate();
+					resource->set_path_cache(path);
+				}
 				text_to_drop += _get_dropped_resource_line(resource, is_empty_line);
 			} else {
 				text_to_drop += _quote_drop_data(path);