migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
1.06k stars 65 forks source link

PackedScene with missing file causes crash when set in an Export #398

Open nvanfleet opened 6 months ago

nvanfleet commented 6 months ago
  1. Create a node subclass
  2. Create an export of packedScene on that class @Export var packedScene: PackedScene?
  3. Create an scene that uses that subclass
  4. Drag a valid packed scene over to the export location in the Godot editor
  5. Quit Godot
  6. Delete the file which was dragged as a packed scene into the export from disk (or rename or move etc)
  7. Restart Godot

What happens: Godot crashes with the information at the bottom of this

Expected to happen: I would expect an PackedScene that has been initialized with a invalid path to ultimately end up returning nil or otherwise being initialized but broken.


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib                 0x180ad20dc __pthread_kill + 8
1   libsystem_pthread.dylib                0x180b09cc0 pthread_kill + 288
2   libsystem_c.dylib                      0x180a15a40 abort + 180
3   Godot                                  0x104fa33d8 0x104c28000 + 3650520
4   libsystem_platform.dylib               0x180b39a24 _sigtramp + 56
5   libSwiftGodot.dylib                    0x11094d0a0 lookupObject<A>(nativeHandle:) + 376 (Wrapped.swift:313)
6   libSwiftGodot.dylib                    0x11094d0a0 lookupObject<A>(nativeHandle:) + 376 (Wrapped.swift:313)
7   libSwiftGodot.dylib                    0x11095bdf4 Variant.asObject<A>(_:) + 256 (Variant.swift:165)
8   libPlantQuest.dylib                    0x10ed7c7e0 CharacterModel._mproxy_set_bodyModel(args:) + 128 (@__swiftmacro_10PlantQuest14CharacterModelC04bodyD06ExportfMp_.swift:6)
9   libPlantQuest.dylib                    0x10ed7eb24 implicit closure #9 in implicit closure #8 in closure #1 in variable initialization expression of static CharacterModel._initializeClass + 4 (@__swiftmacro_10PlantQuest14CharacterModel5GodotfMm_.swift:28) [inlined]
10  libPlantQuest.dylib                    0x10ed7eb24 partial apply for implicit closure #9 in implicit closure #8 in closure #1 in variable initialization expression of static CharacterModel._initializeClass + 12
11  libSwiftGodot.dylib                    0x11093ac8c bind_call(_:classInstance:variantArgs:argc:returnValue:r_error:) + 684 (ClassServices.swift:264)
12  Godot                                  0x108395154 0x104c28000 + 58118484
13  Godot                                  0x1083c12a0 ClassDB::set_property(Object*, StringName const&, Variant const&, bool*) + 344
14  Godot                                  0x1083d4c34 Object::set(StringName const&, Variant const&, bool*) + 152
15  Godot                                  0x1071fa9a0 SceneState::instantiate(SceneState::GenEditState) const + 6328
16  Godot                                  0x1071fc450 PackedScene::instantiate(PackedScene::GenEditState) const + 36
17  Godot                                  0x1071f9c40 SceneState::instantiate(SceneState::GenEditState) const + 2904
18  Godot                                  0x1071fc450 PackedScene::instantiate(PackedScene::GenEditState) const + 36
19  Godot                                  0x105e263e8 EditorNode::load_scene(String const&, bool, bool, bool, bool, bool) + 3288
20  Godot                                  0x105e458a0 EditorNode::_load_open_scenes_from_config(Ref<ConfigFile>) + 468
21  Godot                                  0x105e25574 EditorNode::_load_editor_layout() + 608
22  Godot                                  0x105e251d8 EditorNode::_sources_changed(bool) + 144
23  Godot                                  0x1083da2a8 Object::emit_signalp(StringName const&, Variant const**, int) + 520
24  Godot                                  0x105d73968 0x104c28000 + 18135400
25  Godot                                  0x105d75c44 EditorFileSystem::_notification(int) + 868
26  Godot                                  0x1083d4b08 Object::notification(int, bool) + 80
27  Godot                                  0x10687f728 SceneTree::_process_group(SceneTree::ProcessGroup*, bool) + 232
28  Godot                                  0x10687db7c SceneTree::_process(bool) + 888
29  Godot                                  0x10687e194 SceneTree::process(double) + 240
30  Godot                                  0x104fee468 Main::iteration() + 984
31  Godot                                  0x104f9fbb0 OS_MacOS::run() + 116
32  Godot                                  0x104fcdedc main + 304
33  dyld                                   0x1807890e0 start + 2360
tishin commented 6 months ago

What version of Godot are you using? I can't reproduce this issue on 4.2.1 release. Godot does not let me open a scene with missing dependencies and provides a proper dialog window for fixing them.

nvanfleet commented 6 months ago

What version of Godot are you using? I can't reproduce this issue on 4.2.1 release. Godot does not let me open a scene with missing dependencies and provides a proper dialog window for fixing them.

I am using 4.2.1 but I think you missed my description. The PackedScene is set onto an @Export of my custom SwiftGodot class. It's not in the node tree of the scene.

tishin commented 6 months ago

I think that's what I was trying to do. I have a trivial SwiftGodot class with PackedScene export:

@Godot
final class SomeScene: Node {    
    @Export
    var otherScene: PackedScene?    
}

and its scene file Scene.tscn:

[gd_scene load_steps=2 format=3 uid="uid://hmmqvij3if3d"]

[ext_resource type="PackedScene" uid="uid://cvyspe7pi4ooy" path="res://OtherScene.tscn" id="1_kkivn"]

[node name="Node2D" type="SomeScene"]
otherScene = ExtResource("1_kkivn")

If I delete OtherScene.tscn and restart Godot, it will throw some errors in the console:

 scene/resources/resource_format_text.cpp:448 - res://Scene.tscn:3 - ext_resource, invalid UID: uid://cvyspe7pi4ooy - using text path instead: res://OtherScene.tscn
  Cannot open file 'res://OtherScene.tscn'.
  Failed loading resource: res://OtherScene.tscn. Make sure resources have been imported by opening the project in the editor at least once.
  scene/resources/resource_format_text.cpp:284 - res://Scene.tscn:6 - Parse Error: 
  Failed loading resource: res://Scene.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).

and present a dialog allowing to fix missing dependencies.

nvanfleet commented 6 months ago

What if you load your game with that scene in the main file

On Feb 19, 2024, at 12:42 PM, Mikhail Tishin @.***> wrote:

I think that's what I was trying to do. I have a trivial SwiftGodot class with PackedScene export:

@Godot final class SomeScene: Node {
@Export var otherScene: PackedScene?
} and its scene file Scene.tscn:

[gd_scene load_steps=2 format=3 uid="uid://hmmqvij3if3d"]

[ext_resource type="PackedScene" uid="uid://cvyspe7pi4ooy" path="res://OtherScene.tscn" id="1_kkivn"]

[node name="Node2D" type="SomeScene"] otherScene = ExtResource("1_kkivn") If I delete OtherScene.tscn and restart Godot, it will throw some errors in the console:

scene/resources/resource_format_text.cpp:448 - res://Scene.tscn:3 - ext_resource, invalid UID: uid://cvyspe7pi4ooy - using text path instead: res://OtherScene.tscn Cannot open file 'res://OtherScene.tscn'. Failed loading resource: res://OtherScene.tscn. Make sure resources have been imported by opening the project in the editor at least once. scene/resources/resource_format_text.cpp:284 - res://Scene.tscn:6 - Parse Error: Failed loading resource: res://Scene.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). and present a dialog allowing to fix missing dependencies.

— Reply to this email directly, view it on GitHub https://github.com/migueldeicaza/SwiftGodot/issues/398#issuecomment-1953135548, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALK4P2BKHHBS53H3MN6G3DYUO2K3AVCNFSM6AAAAABDLEKKNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJTGEZTKNJUHA. You are receiving this because you authored the thread.

tishin commented 6 months ago

Same errors, no crash:

W 0:00:00:0412   load: res://Scene.tscn:3 - ext_resource, invalid UID: uid://cvyspe7pi4ooy - using text path instead: res://OtherScene.tscn
  <C++ Source>   scene/resources/resource_format_text.cpp:448 @ load()
E 0:00:00:0412   load: Cannot open file 'res://OtherScene.tscn'.
  <C++ Error>    Condition "err != OK" is true. Returning: Ref<Resource>()
  <C++ Source>   scene/resources/resource_format_text.cpp:1643 @ load()
E 0:00:00:0412   _load: Failed loading resource: res://OtherScene.tscn. 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:275 @ _load()
E 0:00:00:0412   _parse_ext_resource: res://Scene.tscn:6 - Parse Error: [ext_resource] referenced non-existent resource at: res://OtherScene.tscn
  <C++ Source>   scene/resources/resource_format_text.cpp:163 @ _parse_ext_resource()