瀏覽代碼

Merge pull request #103467 from KoBeWi/the_script_you_are_looking_for_is_no_longer_here

Validate custom type script before loading it
Rémi Verschelde 6 月之前
父節點
當前提交
dc128dddb6
共有 2 個文件被更改,包括 8 次插入0 次删除
  1. 1 0
      editor/scene_tree_dock.cpp
  2. 7 0
      scene/property_utils.cpp

+ 1 - 0
editor/scene_tree_dock.cpp

@@ -3115,6 +3115,7 @@ void SceneTreeDock::_replace_node(Node *p_node, Node *p_by_node, bool p_keep_pro
 		// If we're dealing with a custom node type, we need to create a default instance of the custom type instead of the native type for property comparison.
 		// If we're dealing with a custom node type, we need to create a default instance of the custom type instead of the native type for property comparison.
 		if (oldnode->has_meta(SceneStringName(_custom_type_script))) {
 		if (oldnode->has_meta(SceneStringName(_custom_type_script))) {
 			Ref<Script> cts = PropertyUtils::get_custom_type_script(oldnode);
 			Ref<Script> cts = PropertyUtils::get_custom_type_script(oldnode);
+			ERR_FAIL_COND_MSG(cts.is_null(), "Invalid custom type script.");
 			default_oldnode = Object::cast_to<Node>(get_editor_data()->script_class_instance(cts->get_global_name()));
 			default_oldnode = Object::cast_to<Node>(get_editor_data()->script_class_instance(cts->get_global_name()));
 			if (default_oldnode) {
 			if (default_oldnode) {
 				default_oldnode->set_name(cts->get_global_name());
 				default_oldnode->set_name(cts->get_global_name());

+ 7 - 0
scene/property_utils.cpp

@@ -306,5 +306,12 @@ Ref<Script> PropertyUtils::get_custom_type_script(const Object *p_object) {
 		return script_object;
 		return script_object;
 	}
 	}
 #endif
 #endif
+	ResourceUID::ID id = ResourceUID::get_singleton()->text_to_id(custom_script);
+	if (unlikely(id == ResourceUID::INVALID_ID || !ResourceUID::get_singleton()->has_id(id))) {
+		const_cast<Object *>(p_object)->remove_meta(SceneStringName(_custom_type_script));
+		ERR_FAIL_V_MSG(Ref<Script>(), vformat("Invalid custom type script UID: %s. Removing.", custom_script.operator String()));
+	} else {
+		custom_script = ResourceUID::get_singleton()->get_id_path(id);
+	}
 	return ResourceLoader::load(custom_script);
 	return ResourceLoader::load(custom_script);
 }
 }