Skip to content

Give each WebGL context its own graphics data pool - #764

Open
asger-finding wants to merge 1 commit into
phaserjs:masterfrom
asger-finding:fix-graphics-data-pool-per-context
Open

asger-finding wants to merge 1 commit into
phaserjs:masterfrom
asger-finding:fix-graphics-data-pool-per-context

Conversation

@asger-finding

Copy link
Copy Markdown
Contributor

This PR

  • changes the public-facing API
  • is a bug fix

Describe the changes below:

PIXI.WebGLGraphics.graphicsDataPool was shared by all WebGL contexts, and switchMode popped from it without checking the context. So a Graphics in one game could get WebGLGraphicsData whose buffers belong to another game's context, or to a destroyed game's, and then fail every draw with the warning WebGL: INVALID_OPERATION: bindBuffer: object does not belong to this context.

Now each context has its own pool, set in WebGLRenderer#initContext (which also drops pooled buffers of a lost context on restore) and nulled in WebGLRenderer#destroy, alongside PIXI.glContexts and PIXI.instances.

This caused an extremely rare but crazy bug in our game. See below.

To reproduce:

  1. Go to https://tanktrouble.com
  2. Press 2 players and then Local game.
  3. Paste this snippet in the Console:
const throwaway = new Phaser.Game({ width: 1, height: 1, renderer: Phaser.WEBGL, state: { create() {
    const shape = this.add.graphics().beginFill(0xffffff).drawRect(0, 0, 1, 1);
    setTimeout(() => shape.clear(), 100);
    setTimeout(() => throwaway.destroy(), 200);
} } });
  1. Pick up a laser crate and hold an active laser. May require multiple rounds (its a random chance spawn).
    Crate:
image
  1. Bug
image

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant