Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preload target scene got corrupted when attached script has reference of preload-caller script #81685

Open
Tracked by #80877
younggam opened this issue Sep 15, 2023 · 2 comments

Comments

@younggam
Copy link

younggam commented Sep 15, 2023

Godot version

v4.1.1.stable.official [bd6af8e]

System information

Godot v4.1.1.stable - Windows 10.0.19045 - Vulkan (Mobile) - dedicated NVIDIA GeForce RTX 2060 SUPER (NVIDIA; 31.0.15.3713) - Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz (6 Threads)

Issue description

Related with #80877

Preload target scene got corrupted when attached script has reference of preload-caller script

I don't know underneath relations of typed class and preload of scene,
but it causes cyclic reference.
Noticeable things

  1. if one of two script has syntax error, there is no scene corruption error.
  2. if another script has preload-caller script reference, referencing the script in preload-target script also causes corruption error

I think cyclic reference between types doesn't make sense. Even c header can prevent it.

Steps to reproduce

  1. Give class_name to script and declare Enum(for providing easy reference to other script)
  2. preload other scene
  3. Attach script that has type of preload-caller reference to the scene

in foo.gd

class_name Foo
enum MyEnum{A,B,C}

var bar=preload("res://bar.tscn")

in bar.gd

var baz=Foo.MyEnum.A
  1. or any other script that has preload-caller reference

in another.gd

class_name Another
enum YourEnum{A,B,C}

var a=Foo.MyEnum.A

in bar.gd

var baz=Another.YourEnum.A

Minimal reproduction project

t.zip

@nyaxix
Copy link

nyaxix commented Dec 17, 2023

Godot version

v4.2.1.stable.official [b09f793]

System information

Godot v4.2.1.stable - macOS 14.2.0 - Vulkan (Forward+) - integrated Apple M2 Max - Apple M2 Max (12 Threads)

Issue description

This is likely the same issue as above, but an even simpler reproduction. The scene fails to load if it contains an attached script that preloads the scene.

Steps to reproduce

Create a project that contains the main scene, main.tscn, with a single Node called Main. Attached to this node is a script, main.gd, with the following contents:

extends Node

# Comment this line and reload project to uncorrupt scene
# Uncomment this line and reload project to corrupt scene
const Scene = preload("main.tscn")

Save the scene and script and then reload the project. Upon reload, the following errors are shown in the Output window:

 scene/resources/resource_format_text.cpp:284 - res://main.tscn:6 - Parse Error: 
  Failed loading resource: res://main.tscn. Make sure resources have been imported by opening the project in the editor at least once.
  Failed to instantiate scene state of "res://main.tscn", node count is 0. Make sure the PackedScene resource is valid.
  editor/editor_data.cpp:626 - Index p_idx = 1 is out of bounds (edited_scene.size() = 1).

The parsing error references line 6 of the main.tscn file, which is the line that attaches the main.gd script to the Main node. This cyclic dependency between attached script and scene appears to cause the scene to fail to load. Full contents of the main.tscn file is provided below:

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

[ext_resource type="Script" path="res://main.gd" id="1_780mk"]

[node name="Main" type="Node"]
script = ExtResource("1_780mk")

Minimal reproduction project

scene-corruption-repro.zip

@nyaxix
Copy link

nyaxix commented Aug 21, 2024

I've retested this in v4.3.stable.official [77dcf97]

This issue may have been resolved by #93346

My sample project no longer reproduces the issue, and I was unable to reproduce the issue using younggam's attached project either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants