I’m working on a special effect that requires post-processing of a segment of the screen. The perfect tool for this would be the renderer.snapshotArea function. So I followed the sample:
https://phaser.io/examples/v3.85.0/snapshot/view/snapshot-area
Seemed to work, until I modified the sample to add an image to the scene based on the snapshotted texture:
this.input.on('pointerdown', (pointer) => {
const textureManager = this.textures;
this.game.renderer.snapshotArea(pointer.x, pointer.y, 128, 128, (image) => {
document.body.appendChild(image);
if (textureManager.exists('area')) {
textureManager.remove('area');
}
textureManager.addImage('area', image);
this.add.image(0, 0, 'area');
});
});
This code crashes the second time it calls this callback. It works the first click, and fails the second click, giving the following error message:
phaser.min.js:1 Uncaught TypeError: Cannot read properties of null (reading ‘glTexture’)
at initialize.get [as glTexture] (phaser.min.js:1:1032467)
at initialize.batchSprite (phaser.min.js:1:867108)
at initialize.renderWebGL (phaser.min.js:1:247628)
at initialize.render (phaser.min.js:1:846334)
at initialize.render (phaser.min.js:1:48511)
at initialize.render (phaser.min.js:1:967090)
at initialize.render (phaser.min.js:1:954248)
at initialize.step (phaser.min.js:1:76227)
at initialize.step (phaser.min.js:1:80333)
at e (phaser.min.js:1:141058)
Am I doing something wrong? Or is this a bug in the engine? Any help would be appreciated, thanks!