GDScript scripts that reference themselves leak at exit (GDScriptLanguage::finish stops early)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 30/100
Línea de trabajo
Read GDScriptLanguage::finish() and GDScript::clear() in the engine source, then compare Redot’s clear() with the linked Godot fix and Redot pull request #8. Reproduce the shutdown leak with the attached MRP and run the unit suite. Done when the leak no longer appears for the repro and the unit suite passes.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Tested versions
- Reproducible in: v26.3.stable.official [85e520394]
- Also reproducible in an unmodified local build of the same commit.
- Upstream Godot fixed the same bug for 4.7 in godotengine/godot#117991 (issue godotengine/godot#117975). Redot does not have that change yet.
System information
Windows 10 Pro 22H2 (build 19045), x86-64. Reproduced headless (--headless --audio-driver Dummy), so the GPU and renderer are not involved.
Issue description
A project can print these at exit even though it does nothing wrong:
WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
ERROR: 1 resources still in use at exit (run with --verbose for details).
With --verbose the resource is a GDScript, for example Resource still in use: res://holder.gd (GDScript).
Which scripts leak. The leaked script references itself:
- a class that names itself in its own code (
return Holder.new(), orHolder.g()insideclass_name Holder); - or a class that reads its own
static varfrom a function.
Why it comes and goes. It depends on load order, so the leak appears and disappears as unrelated code changes. In a game project it looked like random leaks after each refactor.
Cause. At shutdown, GDScriptLanguage::finish() walks script_list and calls clear() on each script to break those self-references. Each iteration:
- holds the current script in a local
Ref; - clears it;
- moves to the next list node;
- and only then releases the
Ref.
If that Ref was the last one, the script is freed together with its base script. New scripts are added at the front of the list, so a base loaded just before its subclass is exactly the next node. The loop then continues from a freed node, which is a use-after-free. On Windows it usually just stops early, so every script after that point is never cleared and the self-referencing ones leak.
Godot found the same use-after-free with ThreadSanitizer (godotengine/godot#117975) and fixed it in godotengine/godot#117991 by releasing the base script inside GDScript::clear().
Fix available. A Redot version of that fix, for 26.3-stable, is in dominicbytes/redot-engine#8 (single commit e45ed70). Redot's clear() still uses the older ClearData code, so the change goes in the root branch, and it also clears the raw _base pointer that Godot no longer has.
Results:
- This repro: leaks in 5 of 5 runs on the official build, and 0 of 10 with the fix.
- Unit tests: the full suite passes with the fix, 1346 of 1346.
Steps to reproduce
- Create the MRP below.
- Import it once:
redot --headless --path <mrp> --import. - Run it:
redot --headless --audio-driver Dummy --path <mrp>. The main scene quits in_ready(). - The leak warning and error print at exit on every run. Add
--verboseto seeres://holder.gdnamed.
Minimal reproduction project (MRP)
Bugsquad edit:
[!NOTE]
The order in whichmain.gdnamesScreenand thenConfirmmatters; swapping it, or makingConfirmusenew()instead ofConfirm.new(), hides the leak.
gdscript-shutdown-leak-mrp.zip
- Lenguaje dominante
- C++
- Estrellas
- 6.1k
- Forks
- 337
- Merge medio
- 5 d 8 h
- PR fusionados (30 d)
- 13
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Redot-Engine/redot-engine
-
C#] [Export] does not support struct types (GD0102), inconsistent with GDScript struct supportAbiertoenhancement topic:dotnet usability
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Redot-Engine/redot-engine#1589 ·
Los mantenedores suelen responder en 1 día
-
Trait is not being resolvedAbiertobug topic:gdscript
Dificultad 3/5 1-2 días Aptitud para principiantes 48/100
Redot-Engine/redot-engine#1588 ·
Los mantenedores suelen responder en 1 día
-
Handle stateful audio effects when a bus channel becomes inactivePosiblemente ocupada @GeneralProtectionFault la tomó hace 27 días. Abierto
Redot-Engine/redot-engine#1584 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
bug usability
Dificultad 3/5 1-2 días Aptitud para principiantes 53/100
Redot-Engine/redot-engine#1583 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug confirmed topic:3d topic:rendering
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Redot-Engine/redot-engine#1568 ·
Los mantenedores suelen responder en 1 día
Todos los issues de Redot-Engine/redot-engine
Issues similares
-
Make the HTTP server's keep-alive and headers timeouts configurablePosiblemente ocupada @mattgodbolt la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
compiler-explorer/compiler-explorer#9902 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Nixtla/statsforecast#1371 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
[Bug]: pip install -U cudaq-qec fails with a conflict that names cudaq-qec itselfPosiblemente ocupada @fedonman la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
task
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
SparseLinearAlgebra/spla#316 · 1 comentario ·
Los mantenedores suelen responder en 1 día