Shader.preDestroy leaks its ShaderQuad's vertex buffer and VAO on every create/destroy cycle (4.2.1)
Los mantenedores suelen responder en 2 días
@k1epg01ng129-eng ya está trabajando en esto.
Desde el 14/10/2026.
- #7399 de @k1epg01ng129-eng — abierto
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 86/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript
- Área
- game-dev
Línea de trabajo
Comienza en preDestroy en el código fuente del objeto de juego Shader (src/gameobjects/Shader/Shader.js) y rastrea renderNode hasta el ShaderQuad, su WebGLVertexBufferLayoutWrapper y el ProgramManager. Lee cómo WebGLRenderer registra y libera los wrappers (glBufferWrappers, glVAOWrappers, deleteBuffer) para replicar ese patrón con los VAO, posiblemente añadiendo un deleteVAO. Se considera terminado cuando la sonda HTML del issue imprime 0, 0, 0, 0 para ambos contadores, incluido el caso de destrucción antes del primer dibujado, sin liberar el programa compartido ni genericQuadIndexBuffer.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
In WebGL mode, every Shader game object builds its own ShaderQuad render node. The node allocates a vertex buffer
(WebGLVertexBufferLayoutWrapper → renderer.createVertexBuffer, registered in renderer.glBufferWrappers).
On first draw, its ProgramManager creates a VAO per linked program
(renderer.createVAO, registered in renderer.glVAOWrappers).
Shader.preDestroy only nulls this.renderNode. Neither the vertex buffer nor the VAO is released, so both stay registered with the renderer, and their GL objects stay allocated, for the life of the game.
This adds up quickly when shaders are created and destroyed repeatedly. For example, a UI button that draws its background with a Shader and lives in an overlay that is rebuilt on every show leaks one buffer and one VAO per button per show.
Expected: after each create/draw/destroy cycle, the buffer and VAO wrapper counts return to their baseline.
Actual: both counts grow by one per cycle. A shader destroyed before its first draw still leaks its vertex buffer.
Example Test Code
Run against unpatched Phaser 4.2.1:
<!doctype html>
<html>
<body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.js"></script>
<script>
const config = {
name: 'LeakProbe',
fragmentSource: `
precision mediump float;
varying vec2 outTexCoord;
void main() { gl_FragColor = vec4(outTexCoord, 0.0, 1.0); }
`
};
new Phaser.Game({
type: Phaser.WEBGL,
width: 128,
height: 128,
audio: { noAudio: true },
scene: {
create: function () {
const renderer = this.game.renderer;
let baseBuffers = null;
let baseVAOs = null;
let shader = null;
let cycle = 0;
// Each cycle: create a Shader, let it draw once (which creates its VAO), then destroy it.
this.game.events.on('postrender', () => {
if (baseBuffers === null) {
baseBuffers = renderer.glBufferWrappers.length;
baseVAOs = renderer.glVAOWrappers.length;
} else if (shader) {
shader.destroy();
shader = null;
cycle++;
console.log(
`Cycle ${cycle}: retained buffers = ${renderer.glBufferWrappers.length - baseBuffers},`,
`retained VAOs = ${renderer.glVAOWrappers.length - baseVAOs}`
);
}
if (cycle < 4) {
shader = this.add.existing(new Phaser.GameObjects.Shader(this, config, 64, 64, 64, 64));
}
});
}
}
});
</script>
</body>
</html>
Expected counts: 0, 0, 0, 0 for both.
Actual counts: 1, 2, 3, 4 for both.
Additional Information
Releasing the render node's own resources in Shader.preDestroy eliminates the growth:
preDestroy: function ()
{
var renderNode = this.renderNode;
if (renderNode)
{
// Release this Shader's own GL resources. The program and the
// index buffer are shared, so they stay.
var renderer = renderNode.renderer;
var programs = renderNode.programManager.programs;
for (var key in programs)
{
var vao = programs[key].vao;
var vaoIndex = renderer.glVAOWrappers.indexOf(vao);
if (vaoIndex !== -1)
{
renderer.glVAOWrappers.splice(vaoIndex, 1);
}
vao.destroy();
}
renderer.deleteBuffer(renderNode.vertexBufferLayout.buffer);
}
this.renderNode = null;
// ... existing preDestroy body unchanged
}
The shader program is shared through ShaderProgramFactory's key cache, and the index buffer is the renderer's shared genericQuadIndexBuffer, so neither should be deleted here. WebGLRenderer has no VAO counterpart to deleteBuffer, which is why the fix removes the VAO from glVAOWrappers directly. A deleteVAO method on the renderer might be the cleaner upstream shape.
The same leak affects any ShaderQuad-based object that is destroyed; Shader is just the most direct way to reproduce it. The master branch's Shader.preDestroy is unchanged from 4.2.1.
- Lenguaje dominante
- JavaScript
- Estrellas
- 40.5k
- Forks
- 7.2k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
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 phaserjs/phaser
-
Type definition for TilemapLayer.getTileAt is wrongPosiblemente ocupada @hkbughk la tomó hace 10 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 2 días
-
Black opaque background on transparent Phaser.Text textures in Phaser 4.2.1 on older iOS WebGLAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 2 días
-
flipY renders tile incorrectlyPosiblemente ocupada @vtxe02023274 la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 2 días
-
WebGL stroke of a Polygon drops a vertex when its origin-shifted position equals the previous raw vertexPosiblemente ocupada @ICOM725 la tomó hace 47 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
phaserjs/phaser#7361 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
MouseManager.stopListeners never removes the wheel listener — destroyed Game stays retained through the canvasPosiblemente ocupada @schulerj89 la tomó hace 87 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días
Todos los issues de phaserjs/phaser
Issues similares
-
[Bug] Pitch Converter gives the wrong octave for B♯, C♭, B𝄪 and C𝄫Posiblemente ocupada @bhuvan-somisetty la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
sugarlabs/musicblocks#9765 ·
Los mantenedores suelen responder en 1 día
-
documentation good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
adaumsilva/OrchestrAI#51 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Jason-Vaughan/TangleClaw#2546 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
rubyjs/mini_racer#449 ·
-
area:integration enhancement good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100