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

Loading a script that uses it's own class_name creates orphans despite scripts being references #45986

Closed
Ashe opened this issue Feb 13, 2021 · 7 comments

Comments

@Ashe
Copy link

Ashe commented Feb 13, 2021

Godot version:
3.2.3.stable.custom_build (I got it from the AUR)

OS/device including version:
Using GLES3 video driver
OpenGL ES 3.0 Renderer: GeForce GTX TITAN X/PCIe/SSE2
Arch Linux (don't think it's relevant?)

Issue description:
You get a lot of orphan warnings when a script uses it's class name inside itself and it gets loaded without being used. Simply mentioning the class_name anywhere else will bubble up the issue.

ERROR: ~List: Condition "_first != __null" is true.
   At: ./core/self_list.h:112.
ERROR: ~List: Condition "_first != __null" is true.
   At: ./core/self_list.h:112.
WARNING: cleanup: ObjectDB instances leaked at exit (run with --verbose for details).
   At: core/object.cpp:2135.
Leaked instance: GDScriptNativeClass:824
Leaked instance: GDScript:1177 - Resource path: res://broken_class.gd
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: clear: Resources still in use at exit (run with --verbose for details).
   At: core/resource.cpp:477.
Resource still in use: res://broken_class.gd (GDScript)

Steps to reproduce:

# test.gd
extends Node
const SCRIPT_PATH := "res://broken_class.gd";
func _ready():
  var script := load(SCRIPT_PATH);

# broken_class.gd
class_name BrokenClass
extends Node

var variable := false;

func broken_function(BrokenClass: BrokenClass) -> bool:
  return variable == variable;

Minimal reproduction project:
engine_bug.zip

@Ashe
Copy link
Author

Ashe commented Feb 13, 2021

If this is actually intentional (much like you shouldn't use self.set_variable since it causes a recursive dependency) then maybe consider adding a clause in the static typing docs since I didn't see anywhere that there was a rule about using a classes name inside its own file. There's only one for using two classes that depend on each other (which has an in-editor warning and is fine).

@Calinou
Copy link
Member

Calinou commented Feb 13, 2021

Duplicate of #16959?

@Ashe
Copy link
Author

Ashe commented Feb 13, 2021

Duplicate of #16959?

Ah yes, the comments of that bug are certainly related, although the original post seems a little different.

Firstly, in that bug, using 'load' is listed as a work around, but it was the load that triggered the bug for me.

Secondly, that bug is about two scripts loading each other. This is about a script recursively loading itself due to class_name, triggered by a load.

Either way sorry for submitting if it is an issue. I didn't see that other one.

@Calinou
Copy link
Member

Calinou commented Feb 14, 2021

Either way sorry for submitting if it is an issue. I didn't see that other one.

No worries! I can leave this issue open; it sounds different enough.

@qarmin
Copy link
Contributor

qarmin commented Feb 24, 2021

Looks that it may be fixed in Godot 3.2.4(I can't reproduce leak)

@Ashe
Copy link
Author

Ashe commented Feb 24, 2021

Looks that it may be fixed in Godot 3.2.4(I can't reproduce leak)

That's promising news - I think the AUR is still using 3.2.3 so looking forward to fix these things! I guess I should close unless anyone has anything else to add.

@Ashe Ashe closed this as completed Feb 24, 2021
@akien-mga akien-mga added this to the 3.2 milestone Feb 24, 2021
@akien-mga
Copy link
Member

The specific test project in the OP seems fixed in 3.2.4 RC 3 indeed.

There are still similar issues which are reproducible such as #16959 (comment) and #21461 though.

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

4 participants