From 508754ec186ccf1814fbc3b9e799709928614c16 Mon Sep 17 00:00:00 2001 From: Asger Finding Date: Wed, 28 Oct 2026 15:59:50 +0100 Subject: [PATCH] Give each WebGL context its own graphics data pool --- CHANGELOG.md | 14 ++++++++++++++ src/pixi/renderers/webgl/WebGLRenderer.js | 4 ++++ src/pixi/renderers/webgl/utils/WebGLGraphics.js | 11 ++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48001f36a..52a7ce8b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Change Log +## Unreleased + +### API Changes + +- `PIXI.WebGLGraphics.graphicsDataPool` is now an array of pools indexed by WebGL context id. + +### Bug Fixes + +- Fixed WebGL errors when a Graphics object reused pooled WebGL data from another game. + +### Thanks + +@asger-finding + ## Version 2.21.0 - 23 October 2026 ### New Features diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index 97dcff4d3..4f60a7fa1 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -255,6 +255,8 @@ PIXI.WebGLRenderer.prototype.initContext = function () PIXI.instances[this.glContextId] = this; + PIXI.WebGLGraphics.graphicsDataPool[this.glContextId] = []; + // set up the default pixi settings.. gl.disable(gl.DEPTH_TEST); gl.disable(gl.CULL_FACE); @@ -618,6 +620,8 @@ PIXI.WebGLRenderer.prototype.destroy = function () { PIXI.glContexts[this.glContextId] = null; + PIXI.WebGLGraphics.graphicsDataPool[this.glContextId] = null; + this.projection = null; this.offset = null; diff --git a/src/pixi/renderers/webgl/utils/WebGLGraphics.js b/src/pixi/renderers/webgl/utils/WebGLGraphics.js index a4b43ab1e..c4166e068 100644 --- a/src/pixi/renderers/webgl/utils/WebGLGraphics.js +++ b/src/pixi/renderers/webgl/utils/WebGLGraphics.js @@ -126,7 +126,7 @@ PIXI.WebGLGraphics.updateGraphics = function (graphics, gl) { var graphicsData = webGL.data[i]; graphicsData.reset(); - PIXI.WebGLGraphics.graphicsDataPool.push(graphicsData); + PIXI.WebGLGraphics.graphicsDataPool[gl.id].push(graphicsData); } // clear the array and reset the index.. @@ -234,7 +234,7 @@ PIXI.WebGLGraphics.switchMode = function (webGL, type) if(!webGL.data.length) { - webGLData = PIXI.WebGLGraphics.graphicsDataPool.pop() || new PIXI.WebGLGraphicsData(webGL.gl); + webGLData = PIXI.WebGLGraphics.graphicsDataPool[webGL.gl.id].pop() || new PIXI.WebGLGraphicsData(webGL.gl); webGLData.mode = type; webGL.data.push(webGLData); } @@ -244,7 +244,7 @@ PIXI.WebGLGraphics.switchMode = function (webGL, type) if(webGLData.mode !== type || type === 1) { - webGLData = PIXI.WebGLGraphics.graphicsDataPool.pop() || new PIXI.WebGLGraphicsData(webGL.gl); + webGLData = PIXI.WebGLGraphics.graphicsDataPool[webGL.gl.id].pop() || new PIXI.WebGLGraphicsData(webGL.gl); webGLData.mode = type; webGL.data.push(webGLData); } @@ -856,6 +856,11 @@ PIXI.WebGLGraphics.buildPoly = function (graphicsData, webGLData) return true; }; +/** + * Pools of unused WebGLGraphicsData, one per WebGL context id. + * + * @type {Array} + */ PIXI.WebGLGraphics.graphicsDataPool = []; /**