Help: USER ERROR: Condition "_first != nullptr" is true. at: ~List (./core/templates/self_list.h:106)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By keidav

I am getting the following error upon exiting my game:

USER ERROR: Condition "_first != nullptr" is true.
   at: ~List (./core/templates/self_list.h:106)
USER WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
   at: cleanup (core/object/object.cpp:1982)
USER ERROR: Resources still in use at exit (run with --verbose for details).
   at: clear (core/io/resource.cpp:489)

I have read some other threads saying this could be due to a bug or resources not being freed on exit. So I am cleaning up any resources that were allocated before the game exits:

func _notification(what):
	if what == NOTIFICATION_WM_CLOSE_REQUEST:
		if current_scene != null:
			current_scene.queue_free()

Why would I still be getting this error? And would this error also be the reason Godot crashes when exporting for any platform e.g. Windows, Linux and MacOS?

Additional info from export crash:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               Godot [22528]
Path:                  /Applications/Godot.app/Contents/MacOS/Godot
Identifier:            org.godotengine.godot
Version:               4.0.2 (4.0.2)
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2023-04-20 09:36:55.7674 -0700
OS Version:            macOS 13.3.1 (22E261)
Report Version:        12
Anonymous UUID:        39435066-0EB3-2850-842C-83D491EDD039

Sleep/Wake UUID:       D9D08F04-FABE-4F35-AA04-96F98C4006B3

Time Awake Since Boot: 310000 seconds
Time Since Wake:       12331 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGABRT)
Exception Codes:       KERN_INVALID_ADDRESS at 0x00000000000001a8
Exception Codes:       0x0000000000000001, 0x00000000000001a8

VM Region Info: 0x1a8 is not in any region.  Bytes before following region: 105554592661080
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      MALLOC_NANO (reserved)   600058000000-600060000000 [128.0M] rw-/rwx SM=NUL  ...(unallocated)

Application Specific Information:
abort() called


Kernel Triage:
VM - (arg = 0x0) pmap_enter retried due to resource shortage
VM - (arg = 0x0) pmap_enter retried due to resource shortage
VM - (arg = 0x0) pmap_enter retried due to resource shortage
VM - (arg = 0x0) pmap_enter retried due to resource shortage
VM - (arg = 0x0) pmap_enter retried due to resource shortage

keidav | 2023-04-20 16:31

I have run into the same error, and I have had no luck figuring it out. Have you made any progress?

To clarify, I am getting the same starting error message:

ERROR: Condition "_first != nullptr" is true.
at: ~List (./core/templates/self_list.h:106)

I have different errors after that referencing RID allocations being leaked at exit.

pvg | 2023-05-30 17:06

No I have not :frowning:

keidav | 2023-05-30 17:08

I cannot seem to reproduce it on a simpler project, either. I walked back my code to just a few days into the project, and I have the error there, too. Triangulation proved fruitless: I could not find a specific line of code that seemed to cause this. I had hoped to make a smaller project to demonstrate how to get this error so I can report it more usefully on GitHub. I suppose I have had this error for a while, but I didn’t really notice it until I just started exporting for testers.

pvg | 2023-05-30 17:13

I am getting an identical set of errors, but only when running an exported app on a mobile device (via logcat), I can’t reproduce this in the editor:

USER ERROR: Condition "_first != nullptr" is true.
  at: ~List (./core/templates/self_list.h:106)
USER WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
  at: cleanup (core/object/object.cpp:1982)
USER ERROR: Resources still in use at exit (run with --verbose for details).
  at: clear (core/io/resource.cpp:489)

My exports appear to be working though, and this only happens on exit, but I wonder if it leaves any unhandled issues around… Any idea how to run the app with the suggested “–verbose”?

mgc8 | 2023-06-16 01:08

I was able to reproduce at least one instance of this error. It’s reported as fixed for 4.1. Game crashes on exit if closed while awaiting a signal and there are unfreed objects · Issue #78136 · godotengine/godot · GitHub

pvg | 2023-06-16 11:10

Awesome! Thank you…

keidav | 2023-06-16 11:40

Excellent, that’s good to know, thank you!

mgc8 | 2023-06-18 19:47