godotengine / godot

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

Scene with texture resource corrupts when the autoload preload it #80108

Open saierXP opened 1 year ago

saierXP commented 1 year ago

Godot version

from 4.1.dev3 to 4.2.dev

System information

Godot v4.1.dev3 - Windows 10.0.19044 - GLES3 (Compatibility) - AMD Radeon(TM) Vega 8 Graphics (Advanced Micro Devices, Inc.; 31.0.14051.5006) - AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx (8 Threads)

Issue description

autoload game.gd

extends Node
var node = preload("res://scene/node.tscn")

node.tscn One child node sprite with godot icon.

When the project doesn't have a .godot folder (e.g. cloning from github) Opening node.tscn brings up a popup window stating that the scene is corrupt or invalid.

The following error can only be seen on the console(4.1.stable).

ERROR: Unable to open file: res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex.
   at: (scene/resources/texture.cpp:847)
ERROR: Failed loading resource: res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex. Make sure resources have been imported by opening the project in the editor at least once.
   at: (core/io/resource_loader.cpp:273)
ERROR: Failed loading resource: res://icon.svg. Make sure resources have been imported by opening the project in the editor at least once.
   at: (core/io/resource_loader.cpp:273)
ERROR: res://scene/node.tscn:9 - Parse Error:
   at: _parse_node_tag (scene/resources/resource_format_text.cpp:283)
ERROR: Failed loading resource: res://scene/node.tscn. Make sure resources have been imported by opening the project in the editor at least once.
   at: (core/io/resource_loader.cpp:273)

And the editor outputs

scene/resources/packed_scene.cpp:92 - Condition "nc == 0" is true. Returning: nullptr
editor/editor_data.cpp:626 - Index p_idx = 1 is out of bounds (edited_scene.size() = 1).

Restarted the editor, the corrupted message disappeared, and I was able to open the scene normally.

Bisect reveals that the problem stems from the commit Fix multi-threaded resource loading #74405 4.1.dev3

Although this is a minor issue that can be resolved by restarting the editor, I chose to report it anyway, maybe it's related to other scene corruption issues?

Steps to reproduce

  1. Create an autoload with var sceneA = preload(sceneA).
  2. Create a sceneA and add a sprite with a texture.
  3. Exit the editor and delete the .godot folder.
  4. Re-open the project, open sceneA and a message will pop up that the sceneA is corrupted.
  5. Restart the window without deleting the .godot folder, then you can open sceneA normally.
  6. Delete the .godot folder, reopen the editor, and you will find the scene is corrupted again.

editor version >= 4.1.dev3

Minimal reproduction project

AutoLoadPreloadScene.zip

CorporalCrawdad commented 1 year ago

Same issue here, but restarting the editor does not fix for me. I can only open the .tscn in the editor by removing the preload line from the attached script. This is only an editor bug; I cannot open/edit the .tscn in the editor with the preload in place, but everything works fine when running the project.

*edit: My error message differs a bit

scene/resources/packed_scene.cpp:92 - Condition "nc == 0" is true. Returning: nullptr
editor/editor_data.cpp:880 - Index p_idx = 2 is out of bounds (edited_scene.size() = 2).
editor/editor_data.cpp:683 - Index p_idx = 2 is out of bounds (edited_scene.size() = 2).
editor/editor_data.cpp:745 - Index p_idx = 2 is out of bounds (edited_scene.size() = 2).
Attempting to parent and popup a dialog that already has a parent.
loudsoda commented 1 year ago

I too deleted the contents of the .godot folder then reimported it to resolve an unrelated error to only get a set of new problems. I started experiencing this behavior with one of my level in the editor. One odd thing was that I ran the game and teleported to the level in game and it ran just fine. But I could not access the same level in the editor.

Not sure if this is really caused by the same problem, but I experienced similar behavior in 4.1.1

scene/resources/resource_format_text.cpp:283 - res://levels/OutdoorLevel.tscn:444 - Parse Error: 

Failed loading resource: res://levels/OutdoorLevel.tscn. Make sure resources have been imported by opening the project in the editor at least once.

editor/editor_data.cpp:626 - Index p_idx = 1 is out of bounds (edited_scene.size() = 1).