VisualScript resources have references to themselves. Nodes of Function type try to resolve the script from which the function comes and look that script resource up in the ResourceCache. However, this script is itself in the usual case, leading to an indirect dependency on itself.
This causes:
Resources involved in the cycle are never cleaned up.
Resources can't be serialized without the ResourceCache catching the dependency of the Resource on itself. This should be handled in the Resource, which should correctly handle being serialized or deserialized regardless of whether the cache is used.
Steps to reproduce
How to
godot --verbose
create a project
create a node, for example Control
for this top node, create a VisualScript
add a node like "switch" call
save the project
Problem 1
On exit:
Leaked instance: VisualScriptSwitch:-9178347035697301922 - Resource path: res://Control.vs::VisualScriptSwitch_bu1cq
Leaked instance: VisualScript:-9178346485941488033 - Resource path: res://Control.vs
Hint: Leaked instances typically happen when nodes are removed from the scene tree (with `remove_child()`) but not freed (with `free()` or `queue_free()`).
ERROR: Resources still in use at exit (run with --verbose for details).
at: clear (core/io/resource.cpp:479)
Resource still in use: res://Control.vs::VisualScriptSwitch_bu1cq (VisualScriptSwitch)
Resource still in use: res://Control.vs (VisualScript)
Orphan StringName: Control
Orphan StringName: VisualScript
Orphan StringName: ports_changed
Orphan StringName: VisualScriptSwitch
StringName: 4 unclaimed string names at exit.
Problem 2
This problem does not occur in the product today but can be used to easily see the dependency on itself.
Load this resulting *.vs resource with Resource.load(... CACHE_MODE_IGNORE)
This will lead to infinite recursion, and Godot will crash hard with stack limit exceeded, or number of open file handles exceeded, whichever comes first.
Notes
This issue was discussed on #scripting in chat and requested by @theoway
Godot version
v4.0.alpha.calinou.067c1eb92
System information
Windows 10
Issue description
VisualScript resources have references to themselves. Nodes of
Function
type try to resolve the script from which the function comes and look that script resource up in theResourceCache
. However, this script is itself in the usual case, leading to an indirect dependency on itself.This causes:
Resources involved in the cycle are never cleaned up.
Resources can't be serialized without the ResourceCache catching the dependency of the Resource on itself. This should be handled in the Resource, which should correctly handle being serialized or deserialized regardless of whether the cache is used.
Steps to reproduce
How to
godot --verbose
Problem 1
On exit:
Problem 2
This problem does not occur in the product today but can be used to easily see the dependency on itself.
Load this resulting *.vs resource with
Resource.load(... CACHE_MODE_IGNORE)
This will lead to infinite recursion, and Godot will crash hard with stack limit exceeded, or number of open file handles exceeded, whichever comes first.
Notes
This issue was discussed on
#scripting
in chat and requested by @theowayMinimal reproduction project
No response