godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.93k stars 20.17k forks source link

Project corrupts when a project setting has a custom resource as its value #96219

Open elmarhoppieland opened 2 weeks ago

elmarhoppieland commented 2 weeks ago

Tested versions

v4.3.stable.official [77dcf97d8]

System information

Godot v4.3.stable - Windows 10.0.22631 - Vulkan (Forward+) - integrated Intel(R) UHD Graphics (Intel Corporation; 27.20.100.9415) - Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz (8 Threads)

Issue description

After executing the following code:

# plugin.gd
@tool
extends EditorPlugin

func _enter_tree() -> void:
    ProjectSettings.set_setting("corrupt/test/resource", CustomResource.new())
# CustomResource.gd
extends Resource
class_name CustomResource

And then reloading the project, the following happens:

  1. The project doesn't reopen after closing.
  2. After opening the project manager manually, the project manager says the project is missing from the file system. However, opening the location of the project in file explorer, it is still there. Hovering over the warning symbol shows "This project uses features unsupported by the current build: Unknown version". image

Opening the project's project.godot file and changing test/resource=Object(Resource,"resource_local_to_scene":false,"resource_name":"","script":Resource("res://CustomResource.gd")) to test/resource=Object(Resource,"resource_local_to_scene":false,"resource_name":"") (removing the resource's script) fixes the problem and after reloading the project manager the project shows up normally.

Steps to reproduce

  1. Create a new project.
  2. Create a new script that extends Resource and give it a class_name.
  3. Create a plugin.
  4. In the plugin's _enter_tree() function, set a custom project setting to an instance of the resource defined above.
  5. Disable and re-enable the plugin to run the code.
  6. Attempt to reload the project (and see that it does not reopen).
  7. Open the project manager and see that the project is corrupted.
  8. Open the project's project.godot file and remove the script=Resource(...) from the value of the new setting.
  9. Close and reopen the project manager and see that the project is not corrupted.

Minimal reproduction project (MRP)

Corrupt.zip

elmarhoppieland commented 2 weeks ago

Another bug that happens to one of my projects which attempts to use custom resources in the settings is that when running the project it instead runs the project manager. I don't think this happens to other projects that use custom resources but removing the custom resources does fix it so it's most likely related.

This does have the side effect that I can see the project manager's output and error logs which may be helpful:

Output log:

Project is missing: C:/Documenten/Project Settings Corrupt Test/project.godot
Project is missing: C:/Documenten/Corrupt/project.godot
Error log:

E 0:00:01:0996   load_source_code: Attempt to open script 'res://CustomResource.gd' resulted in error 'File not found'.
  <C++ Error>    Condition "err" is true. Returning: err
  <C++ Source>   modules/gdscript/gdscript.cpp:1094 @ load_source_code()
E 0:00:01:0996   _load: Failed loading resource: res://CustomResource.gd. Make sure resources have been imported by opening the project in the editor at least once.
  <C++ Error>    Condition "found" is true. Returning: Ref<Resource>()
  <C++ Source>   core/io/resource_loader.cpp:283 @ _load()
E 0:00:01:0996   _parse: ConfigFile parse error at C:/Documenten/Project Settings Corrupt Test/project.godot:19: Can't load resource at path: 'res://CustomResource.gd'..
  <C++ Source>   core/io/config_file.cpp:304 @ _parse()
E 0:00:01:0997   load_source_code: Attempt to open script 'res://CustomResource.gd' resulted in error 'File not found'.
  <C++ Error>    Condition "err" is true. Returning: err
  <C++ Source>   modules/gdscript/gdscript.cpp:1094 @ load_source_code()
E 0:00:01:0997   _load: Failed loading resource: res://CustomResource.gd. Make sure resources have been imported by opening the project in the editor at least once.
  <C++ Error>    Condition "found" is true. Returning: Ref<Resource>()
  <C++ Source>   core/io/resource_loader.cpp:283 @ _load()
E 0:00:01:0997   _parse: ConfigFile parse error at C:/Documenten/Corrupt/project.godot:17: Can't load resource at path: 'res://CustomResource.gd'..
  <C++ Source>   core/io/config_file.cpp:304 @ _parse()

I'm not sure whether I should open a new issue since I can't consistently reproduce it and it seems to be a direct result of this bug.