godot: Scene corruption after forced reboot on Linux
Tested versions
v4.2.stable.official [46dc27791]
System information
Ubuntu 22.04 - v4.2.stable.official [46dc27791]
Issue description
Believe I did a sudo reboot now and was able to trigger a non-proper flushing of the file causing a corruption
scene/resources/resource_format_text.cpp:284 - res://scenes/game/Bullet.tscn:10 - Parse Error:
Failed loading resource: res://scenes/game/Bullet.tscn. Make sure resources have been imported by opening the project in the editor at least once.
Failed to instantiate scene state of "res://scenes/game/Bullet.tscn", node count is 0. Make sure the PackedScene resource is valid.
Failed to instantiate scene state of "res://scenes/game/Bullet.tscn", node count is 0. Make sure the PackedScene resource is valid.
Failed to instantiate scene state of "res://scenes/game/Bullet.tscn", node count is 0. Make sure the PackedScene resource is valid.
Bullet.tscn
[gd_scene load_steps=4 format=3 uid="uid://bpw08h6qjtf80"]
[ext_resource type="Texture2D" uid="uid://87j7ldt0dsn7" path="res://icon.svg" id="1_rqlw1"]
[ext_resource type="Script" path="res://scenes/game/Bullet.gd" id="1_v4orp"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_21qps"]
size = Vector2(32, 32)
[node name="Area2D" type="Area2D"]
script = ExtResource("1_v4orp")
[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.25, 0.25)
texture = ExtResource("1_rqlw1")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
texture_filter = 1
shape = SubResource("RectangleShape2D_21qps")
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
Steps to reproduce
Probably have the script opened in a potentially unsaved state and force a reboot…
Minimal reproduction project (MRP)
N/A
About this issue
- Original URL
- State: open
- Created 7 months ago
- Reactions: 1
- Comments: 25 (5 by maintainers)
thanks to @isaaccp I just found this issue here, I created almost the same issue #86154
I debugged this as much as I can.
First some workarounds that helped with loading:
So, like just said, the underlying reason is that a script failed to parse during load of the scene and then the scene stays corrupted until you reload the project. One specific condition I found to cause this is using the preload statement. preload is followed through while parsing during opening the project. This will fail to parse if the preload in a chain leads back to the scene that’s not yet instantiated because currently being loaded. There may be other conditions.
The bad thing about this is that a user will think all their work is ruined even though there are some easy fixes to load the scenes again.
What I already suggested in #86154 is to change the loading in the editor such that scripts are parsed after the scene has been instantiated. The necessary code edits are too far reaching that I don’t yet dare creating a pull request, yet.
Here is the live video though I think the video will only be valid on Twitch for 7-60 days.
Here are the key points:
Bullet.tscnBullet.tscnand start a new fileTest123.tscnTest123.tscnis now corruptTest123.tscnhas now somehow uncorruptedBullet.tscn@onreadyand change the gdscript back toBullet.tscnwithout any issue and reload Godot and have no issues now@akien-mga I hope all the core contributors watch the ~35 minutes at 2x speed to see the level of frustration as a new Godot user hitting this kind of bug. If I recall I have some harsh words said in the stream along the lines of, “This literally makes me want to quit using Godot.”
bug’s already fixed, 4.3 just needs to get to a stable release
I just had the same problem.
I solve it by:
The script attached to my corrupted scene doesn’t have PackedScene as a variable but contains the line with
preload("My Scene.tscn")I just had the same problem and removing the .godot folder made the scene work again. I kept the old .godot folder and the differences on the .tscn file are:
Old one:
new one:
Hope this helps.
That
Bullet.tscndoesn’t seem corrupted. I can open it fine if copy pasting it to a project (after making sure to create a script atscenes/game/Bullet.gd).Do you still get this issue after restarting the editor?
What about if you rename the
.godotfolder to something else, so it’s re-created? (Please keep it around at first, because if that fixes the issue, checking the diff between the two folders could give a hint at to what the problem is.)Also had this problem (4.2.1 Linux). Following goatt1167’s comment made the scene openable again.
It is worth to point out that I had an issue with circular references - the script in the corrupted scene (scene A) was preloading another scene (scene B), but the script in scene B was also preloading scene A. An oversight and not an intentional design. I think that it could easily happen to other developers without noticing. Maybe this could be checked for and given as a warning when failing to open scenes?
Ran into the same issue. For me I was preloading the scene the script itself was attached to. The corruption message went away after changing
preloadto justload.Been experiencing this on Windows, Godot 4.2.1, For the last week. Have re-created the scene many times but the issue comes back.
The quoted post solved it for me, i.e. using explicit typing instead of inferred:
var scene := preload("res://test/scene/creeper/creeper.tscn")becomes this:
var scene:PackedScene = preload("res://test/scene/creeper/creeper.tscn")So my scene file is fine, there’s something happening during the load of the scene. Haven’t dared close Godot yet so don’t know if it will work long term.
Edit: Reopened Godot, the issue is back 😦
This is written in the error log:
encountering the same issue on the steam windows v4.2.1.stable.official[b09f793f5] build for my own project 😒 deleted the
.godotfiles to refresh the cache but the issue persisted. project runs fine with the corrupted filecan second this; the only thing that is preloaded in my project is the only scene thats corrupting
Interesting, the scene that was corrupted on my side had a script with
constvariables containingPackedScenestoo.