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

Circular script preloading causes leak without warning (both with preload or named classes) #16959

Open
Zylann opened this issue Feb 23, 2018 · 14 comments

Comments

@Zylann
Copy link
Contributor

Zylann commented Feb 23, 2018

Godot 2.1.5 beta, Godot 2.1.4, Windows 10 64 bits

I found out my project had a circular dependency between two scripts which were preloading each other into a const (though the game has worked perfectly fine so far, it's been a year).
The use case was only to use extends on it. Workaround is to use load...

The result of this is a random memory leak (which doesn't always happen) and two cryptic errors:

ERROR: SelfList<class GDFunction>::List::~List: Condition ' _first != 0 ' is true.
   At: core\self_list.h:80
ERROR: SelfList<class GDScript>::List::~List: Condition ' _first != 0 ' is true.
   At: core\self_list.h:80
WARNING: ObjectDB::cleanup: ObjectDB Instances still exist!
     At: core\object.cpp:1845
ERROR: ResourceCache::clear: Resources Still in use at Exit!
   At: core\resource.cpp:378

Reproduction project;
CircularScriptPreload.zip

@Zylann Zylann changed the title ObjectDB leaks an object Circular script preloading causes leak without warning Feb 23, 2018
@Ranoller
Copy link
Contributor

Are you using some module?

@Zylann
Copy link
Contributor Author

Zylann commented Feb 23, 2018

@Ranoller no, just official Godot 2.1.4.

@Ranoller
Copy link
Contributor

No idea then... DragonBones module gives to me ObjectDB Instances still exist! on app exit, but only on exit (and i´m going to report that right now)

@Zylann
Copy link
Contributor Author

Zylann commented Feb 23, 2018

To me it's quite obvious: there is a circular reference. Now I'm not sure if that's really intented to produce one or not. If it is, would be nice to show a warning when the resource gets loaded.

@Ranoller
Copy link
Contributor

No error until close with your test.
On quit there are the 2 first mensagges (GDFunction and GDScript).
Last two messages aren´t printed.

@Ranoller
Copy link
Contributor

Second time that executes the four messages are printed.

@Zylann
Copy link
Contributor Author

Zylann commented Feb 23, 2018

@Ranoller it's random :p

@Geequlim
Copy link
Contributor

Related to #15839

@akien-mga
Copy link
Member

According to #15839 (comment):

This is not a bug, this is a feature. It's in the GDScript documentation. Any cycles are leaked.

@akien-mga akien-mga added discussion and removed bug labels Mar 2, 2018
@KoBeWi
Copy link
Member

KoBeWi commented Mar 8, 2018

Uh, I have the same issue, but I don't know what is causing it. I'm not using cyclic preloading anywhere (at least not intentionally) and the issue seems to appear only in exported project. Is there a way to trace the problem? I'm using Godot 3.0.2

@Zylann
Copy link
Contributor Author

Zylann commented Mar 8, 2018

@KoBeWi what is your complete log of errors? The one about the leak can be caused by many things, not just cyclic refs

@KoBeWi
Copy link
Member

KoBeWi commented Mar 8, 2018

It's the same as here, but with different line numbers (probably because of Godot version):

ERROR: SelfList::List::~List: Condition ' _first != 0 ' is true.
At: c:\projects\godot-builds\godot\core\self_list.h:100
ERROR: SelfList::List::~List: Condition ' _first != 0 ' is true.
At: c:\projects\godot-builds\godot\core\self_list.h:100
WARNING: ObjectDB::cleanup: ObjectDB Instances still exist!
At: core\object.cpp:1989
ERROR: ResourceCache::clear: Resources Still in use at Exit!
At: core\resource.cpp:418

@KoBeWi
Copy link
Member

KoBeWi commented Apr 29, 2019

Looks like in 3.1 you are prevented from circular preloading:
E 0:00:00:0683 Resource: 'res://new_script.gd' is already being loaded. Cyclic reference?

@akien-mga akien-mga changed the title Circular script preloading causes leak without warning Circular script preloading causes leak without warning (both with preload or named classes) Feb 3, 2021
@akien-mga akien-mga added the bug label Feb 3, 2021
@akien-mga
Copy link
Member

akien-mga commented Feb 3, 2021

I can confirm the issue in 3.2.4 RC 1, and it happens with class_name too when you reference the current class in itself, e.g.:

extends Node
class_name MyNode

var test : MyNode = null

It appears to be fixed in master, but a fix for 3.2 would still be very welcome.

Related to / partial duplicate of #21461.

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

6 participants