What is causing this error upon exit? "ERROR: SelfList<class GDFunction>::List::~List: Condition ' _first!=0 ' is true"

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Genji
:warning: Old Version Published before Godot 3 was released.

Hello, fellow Godot users. I’m fairly new to using the engine and have a minor problem.

I get the following two error messages upon exiting my game:

"ERROR: SelfList<class GDFunction>::List::~List: Condition ' _first!=0 ' is true"
At: core\self_list.h:82
"ERROR: SelfList<class GDScript>::List::~List: Condition '  _first!=0 ' is true"
At: core\self_list.h:82

Looking at where the error refers to…
https://github.com/godotengine/godot/blob/master/core/self_list.h
…my guess is that one or more of my GDScript files are still in use when the game exists, so the list keeping track of them can’t completely free its resources.

Can anyone shed some light on this and help me understand these errors?

Thanks in advance!

ERROR: ~List: Condition “_first != __null” is true.
At: ./core/self_list.h:112
Should this not be a warning??
still exists in 3.2.3 and yes I load the resources. shows up in executable on windows.

I don’t always have the scene that created the instance so when exiting tree they have to be located … so ignoring this is not ok … how do we hide this?

docs show
func _exit_tree():
# When the node exits the Scene Tree, this function is called.
# Children nodes have all exited the Scene Tree at this point
# and all became inactive.
pass

crazyhat62 | 2020-09-26 07:32

Hey, i had the same problem with memory leaks. my problem was that I was instancing the node but not adding to the scene tree. I have a habit of making dictionaries instead of if/else statements like:

func doSomething(value: int):
var dic = {
1: load(“res://somethin1.tscn”).instance()
2: load(“res://somethin2.tscn”).instance()
}

       var object = dic.get(value)

The dictionary is wrong because i instance 2 objects, but i am only using one of them; when i close the game, that unused object will leak. I fixed it by just wring the absolute path in the dic and instancing the object that i actually use.

The best way to find these problems is to use --verbose. You do so by going to your computer’s cmd and writing the absolute path of you godot + the application.exe and adding space follow by the --verbose keyword. like this:

C:\Users\name\> cd C:\Users\name\deskstop\godot.v3.3.exe --verbose

ebersouto008 | 2022-10-16 21:53

:bust_in_silhouette: Reply From: Genji

OK, so I think the errors are the editor’s way of complaining that there were resources, in general, which were not freed upon exiting the application.

For instance, doing something like…

var local_scene = null
func _ready():
    var resource = load("res://MyScene.tscn")
    local_scene = resource.instance()

# Ignore responsibility for freeing 'local_scene'
func _exit_tree():
    pass

…seems to trigger the two errors. But it can be resolved by calling .free() on the variables using instanced resources:

func _exit_tree():
    local_scene.free()

Additionally, it seems like .queue_free() might NOT work in some cases. I will update my findings when I learn more.

Any comments, corrections, or feedback in the meantime would be appreciated.

:bust_in_silhouette: Reply From: Favarete

Hello, friend.
I was getting the same error after closing my game. The only thing that worked for me was making my own signal.

Declaring the signal close to the variables

signal destroyed

Using it with queue_free()

queue_free()
emit_signal("destroyed")

And calling it in the place of exit_tree in connect

local_scene.connect("destroyed",self,"function_to_use")

No more error for me after that. Hope it helps you or others with similar problems.

:bust_in_silhouette: Reply From: Matt_UV

Hello,
I think this is a bug, and I succeeded in isolating it.

As I don’t know how to fix it, I created an issue:

Maybe someone will be able to help us!