Memory leak in TilemapLayerWebGLRenderer

Aperta
#7,296 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
javascript

Direzione di ricerca

Inizia da src/tilemaps/TilemapLayerWebGLRenderer.js ed esamina gli oggetti a livello di modulo e l’assegnazione di texturerData.frame.source.glTexture durante il rendering. Riproduci il ciclo con l’esempio fornito di creazione e distruzione di Phaser.Game, quindi verifica tramite misurazioni dell’heap che la memoria trattenuta da TilemapLayerWebGLRenderer non aumenti più dopo cicli ripetuti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Version

  • Phaser Version: 4.0.0
  • Operating system: MacOS Monterey v12.7.6
  • Browser: all browsers

Description

When Phaser.Game is destroyed and a new instance is created on the same page, retained heap memory for TilemapLayerWebGLRenderer nearly doubles with each cycle.

Example Test Code (in phaser sandbox)

class MainScene extends Phaser.Scene {

    constructor() {
        super({ key: "MainScene" });
    }

    preload() {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v385');
        this.load.image('walls_1x2', 'assets/tilemaps/tiles/walls_1x2.png');
    }

    create() {
        const map = this.make.tilemap({ width: 200, height: 200, tileWidth: 32, tileHeight: 32 });
        const tiles = map.addTilesetImage('walls_1x2', null, 32, 64);

        const layer = map.createBlankLayer('layer1', tiles);

        layer.randomize(0, 0, map.width, map.height, [ 0, 1, 2, 3, 4, 5, 6, 7 ]);
    }
}

let game = null;
const getGame = () => game;

function createGame() {
    game = new Phaser.Game({
        type: Phaser.AUTO,
        width: 800,
        height: 800,
        backgroundColor: '#111111',
        scale: {
            mode: Phaser.Scale.FIT,
            autoCenter: Phaser.Scale.CENTER_BOTH
        },
        scene: [ MainScene ]
    });
}

function destroyGame(gameInstance) {
    gameInstance.events.once('destroy', () => {
        game = null;
    });

    gameInstance.destroy(true);
}

setInterval(() => {
    if (!getGame()) {
        createGame();
    } else {
        destroyGame(getGame());
    }
}, 6000);

Additional Information

Possible issue at src/tilemaps/TilemapLayerWebGLRenderer.js :
Module-level singleton retains glTexture reference across Phaser.Game instances. Declares two module-level objects that persist for the entire lifetime of the JavaScript module (i.e. they are never GC'd).
During every render call, the live glTexture from the active Tileset is written into texturerData:
texturerData.frame.source.glTexture = tileset.glTexture;

When WebGLRenderer.destroy() is called (via game.destroy()), it correctly iterates glTextureWrappers and calls .destroy() on each. However, texturerData.frame.source.glTexture is never nulled out.

Lingua principale
JavaScript
Stelle
40.7k
Fork
7.2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di phaserjs/phaser

Tutte le issue di phaserjs/phaser

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.