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

[TRACKER] Issues with preload cache #85081

Closed
8 tasks done
KoBeWi opened this issue Nov 19, 2023 · 12 comments
Closed
8 tasks done

[TRACKER] Issues with preload cache #85081

KoBeWi opened this issue Nov 19, 2023 · 12 comments

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Nov 19, 2023

Godot version

4.2 rc1

System information

Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 (NVIDIA; 30.0.15.1403) - Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 Threads)

Issue description

When you preload() a script or a scene (or possibly anything else), that resource will stay in memory in its original form and it's difficult to remove or update it. This leads to all sorts of issues, particularly when the initial loading fails the resource will be broken until editor restart or in worst case until the user performs some magic to fix the cached version (when restarting doesn't work).

Here's the list of issues caused by this behavior:

These two issues are solved, but they were related, so adding for context:

Related PRs (they don't fix the problem, but band-aid it partially):

Steps to reproduce

  1. Use preload()
  2. Pray it won't cause problems (it will 😉)

Minimal reproduction project

N/A

@Jordyfel
Copy link
Contributor

#83187 OP's update says that this issue is caused by preload as well

@akien-mga
Copy link
Member

@Swarkin
Copy link
Contributor

Swarkin commented Dec 8, 2023

Changing all preloads to load seems to be a viable workaround for now.
My project doesn't seem to be corrupting the scenes anymore with that change.

@Jordyfel
Copy link
Contributor

#85986

@adamscott adamscott changed the title Issues with preload cache [TRACKER] Issues with preload cache Jan 8, 2024
Kazuren added a commit to Kazuren/godot-editor-theme-explorer that referenced this issue Feb 22, 2024
@ndbn
Copy link

ndbn commented Mar 22, 2024

It seems very relative to this.
Simple scene with only Line2D root node and attached script:

extends Line2D
class_name FishingLineScene

const FISHING_LINE: PackedScene = preload("res://scenes/player/fishing/fishing_line.tscn")

static func createScene() -> FishingLineScene:
  var scene: FishingLineScene = FISHING_LINE.instantiate()
  return scene

func add_point_from_global(global_point: Vector2) -> void:
  self.add_point(self.to_local(global_point))

In 4.3dev5:
When project loaded:

 scene/resources/resource_format_text.cpp:291 - Parse Error: Busy. [Resource file res://scenes/player/fishing/fishing_line.tscn:8]
  Failed loading resource: res://scenes/player/fishing/fishing_line.tscn. Make sure resources have been imported by opening the project in the editor at least once.
  res://scenes/player/fishing/fishing_line.gd:4 - Parse Error: Could not preload resource file "res://scenes/player/fishing/fishing_line.tscn".
  modules/gdscript/gdscript.cpp:2859 - Failed to load script "res://scenes/player/fishing/fishing_line.gd" with error "Parse error". (User) 

Scene succesfully opened in editor and work at runtime

In 4.2.1:
Error output when project reloaded:
Failed to instantiate scene state of "res://scenes/player/fishing/fishing_line.tscn", node count is 0. Make sure the PackedScene resource is valid.
Error message box when this scene opened:
image
But running project with F5 works well, even creating this scene.

A working analog without any errors for both versions is using below instead const and preload:

static var FISHING_LINE: PackedScene = load("res://scenes/player/fishing/fishing_line.tscn")

@GustJc
Copy link
Contributor

GustJc commented Apr 18, 2024

Here's another issue with cyclic scene references. That is still happening in 4.3-dev5 (mono)
Not sure if this is being tracked here. Or if it should be in #83187

I can set a PackedScene @export var in scene 1.tscn to 2.tscn
And a PackedScene @export var in scene 2.tscn to 1.tscn

Everything still works.
I can save, close, and re-open the scenes without problems.

But after reloading the project, the scenes can't be opened again and are corrupt due to the cyclic reference

I think that behavior might take a few people by surprise due to only happening after the reload.

@akien-mga akien-mga modified the milestones: 4.3, 4.4 Jun 18, 2024
@paskausks
Copy link

paskausks commented Aug 15, 2024

I started getting this issue in one of my scenes after upgrading my main project to v4.3.stable.official [77dcf97d8].

Nuking the .godot folder and reimporting everything didn't fix it. Changing the line which loads the affected packed scene from const foo = preload(...) to var foo = load(...) fixed it.

Another thing that fixed it is basically similar to what others have suggested to do in this case - i duplicated the affected scene and the script attached to that scene, then used a text editor to change the script reference in the scene copy to the copy of the script, and then changed the preload() call to the path of the copy. IIRC, I didn't even restart the godot editor when I did that.

The affected scene itself isn't anything spectacular, it's just a single Control node with an attached script which talks to some singletons (maybe there's a cyclic dependency in there, but if there is, it's indirect), accepts a node reference an does animations with it. I have to note that this scene didn't cause issues with 4.2, and I'm fairly sure it was in the project during 4.1 as well, where it worked just fine.

@MewPurPur
Copy link
Contributor

MewPurPur commented Aug 17, 2024

I encountered this in 4.3.stable too, and it seems like it's a recent regression since I had a similar setup in 4.3.beta3 but no crash (I'm not 100% sure about this, but maybe 95%). Godot told me that "I can't assign something of type LineEdit to be a BetterLineEdit" when the node was very much of type BetterLineEdit. So I got bad error reporting and had to investigate it myself.

I commented out everything with ContextPopup inside the BetterLineEdit code, the error disappeared. Then I commented out stuff in my ContextPopup class_name, and continued on. What I got was the following:

  • BetterLineEdit class_name references the ContextPopup class_name.
  • ContextPopup references a HandlerGUI singleton.
  • The HandlerGUI singleton preloads a settings menu scene.
  • The settings menu scene has a script which preloads another scene, which preloads yet another scene of a dropdown widget.
  • The dropdown widget scene has a script which contains BetterLineEdit.

I broke the chain by making the singleton not use preloads, and the crashes stopped. Maybe the crash itself is valid, but Godot shouldn't have given me a bogus error.

I want to figure out how to make an MRP for a bug report, but for now I'm just confirming @paskausks's experience.

@KoBeWi
Copy link
Member Author

KoBeWi commented Aug 17, 2024

Closing. The tracker was listing issues related to "preload cache", which I think is no longer a thing. All originally linked issues have been resolved and the others aren't related to this particular problem.

@KoBeWi KoBeWi closed this as completed Aug 17, 2024
@KoBeWi KoBeWi modified the milestones: 4.4, 4.3 Aug 17, 2024
@nihiluis
Copy link

nihiluis commented Sep 25, 2024

@KoBeWi where is this issue tracked now? I suddenly got this issue (same as ndbn above) out of nowhere on 4.3 stable, something is definitely broken.

@KoBeWi
Copy link
Member Author

KoBeWi commented Sep 25, 2024

Open a new issue. It might have different cause.

@k21
Copy link

k21 commented Oct 1, 2024

I was seeing an error similar to the one reported by #85081 (comment) so I opened a new issue here: #97684

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

No branches or pull requests

10 participants