Pixi.js: WebGL Context Regression

Created on 6 Aug 2019  路  6Comments  路  Source: pixijs/pixi.js

Hello! I am developing a pixi app which has to create and destroy lots of PIXI canvases. I've been using PIXI 5.0.4 until recently when I tried to upgrade to 5.1.1.

When I destroy a canvas, I use app.destroy() to destroy the WebGL context. If I run the app without refreshing for a while, eventually I get the following message:

scripts.js:1 WARNING: Too many active WebGL contexts. Oldest context will be lost.
e.createContext @ scripts.js:1

In PIXI 5.0.4, this warning is all that happens and PIXI happily creates a new WebGL context when I ask it to.

In PIXI 5.1.0 and above, I get the same warning and then an error:

scripts.js:1 WARNING: Too many active WebGL contexts. Oldest context will be lost.
e.createContext @ scripts.js:1
/main-es2015.js:1 ERROR TypeError: Failed to execute 'shaderSource' on 'WebGL2RenderingContext': parameter 1 is not of type 'WebGLShader'.

After I get this message, I can't create any new WebGL contexts without refreshing the page. I tried reverting my project to use PIXI 5.0.4 and this error went away.

I'm not a WebGL guru, but noticed that #5872 touches on code that's somewhat related.

Most helpful comment

@JetLua that's a good solution. Fancy submitting a PR?

ok, I'll submit a PR.

All 6 comments

OK, that's interesting. Please give more info. Is that in chrome or in firefox? Can you make a simple demo please? My telepathy doesn't work properly on that case and there were multiple people that messed with contexts initialization, so we really need the demo and more info.

Sure! I see this happen in Chrome (75) and Firefox (68).

I made a short example:
v5.1.0: https://pixiplayground.com/#/edit/m2uYajft~ZRxeTrFQbix6
v5.0.4: https://pixiplayground.com/#/edit/4UmnnyPSGRuUHbmAG2cDP

In both browsers v5.0.4 works as expected while v5.1.0 shows the error (wording of it is a bit different in Firefox) after about 16 seconds (once there's more than 16 contexts).

https://github.com/pixijs/pixi.js/blob/985ce5897d91ec76a6aac60c0c72c78015a1f3f2/packages/core/src/shader/utils/getTestContext.js#L16

Try a fix, maybe there's a better one.

if (context === unknownContext || context.isContextLost())

I just updated to 5.1.4 and I'm still experiencing this issue. Any updates on this?

@JetLua that's a good solution. Fancy submitting a PR?

@JetLua that's a good solution. Fancy submitting a PR?

ok, I'll submit a PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sntiagomoreno picture sntiagomoreno  路  3Comments

lucap86 picture lucap86  路  3Comments

readygosports picture readygosports  路  3Comments

MRVDH picture MRVDH  路  3Comments

softshape picture softshape  路  3Comments