Pixi.js: Invalid value of `0` passed to `checkMaxIfStatementsInShader`

Created on 12 Dec 2017  路  2Comments  路  Source: pixijs/pixi.js

Hey! 馃憤

I am doing some work with Angular and a Canvas just now which is actually not the best documented thing out there. Anyway I was messing around with Pixi, and I extend PIXI.Application. When I try to destroy the application, I always hit this error.

https://github.com/pixijs/pixi.js/blob/0faef4fa3bcd0af8dba3a589bf4ddb7716b4c62a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js#L19

Does anyone know why this line would be triggered?

Thanks 馃拑

馃 Question

Most helpful comment

I met the same problem today and got this solved my way.

I tried to cache canvas rendered by PIXI.WebGLRenderer when it's removed from DOM tree so that I could reuse this canvas rather than instantiate a new one when I need to render again. And I met this problem when the reused canvas was rendered.
I solved this problem by caching WebGLRenderingContext of WebGLRenderer as well.

Key error stack of this problem is in SpriteRenderer.js:
this.MAX_TEXTURES = Math.min(gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS), settings.SPRITE_MAX_TEXTURES);
The result of gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS) is 0.
The gl here is created by glCore.createContext(this.view, this._contextOptions);, content of which is

var createContext = function(canvas, options)
{
    var gl = canvas.getContext('webgl', options) || 
         canvas.getContext('experimental-webgl', options);
    if (!gl)
    {
        // fail, not able to get a context
        throw new Error('This browser does not support webGL. Try using the canvas renderer');
    }
    return gl;
};

I don't find any problem of the gl context creation.

So I guess the reason of the problem is that the texture units of this canvas is used by the former gl context and there is none left for the second gl context, so gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS) gets 0.

All 2 comments

I met the same problem today and got this solved my way.

I tried to cache canvas rendered by PIXI.WebGLRenderer when it's removed from DOM tree so that I could reuse this canvas rather than instantiate a new one when I need to render again. And I met this problem when the reused canvas was rendered.
I solved this problem by caching WebGLRenderingContext of WebGLRenderer as well.

Key error stack of this problem is in SpriteRenderer.js:
this.MAX_TEXTURES = Math.min(gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS), settings.SPRITE_MAX_TEXTURES);
The result of gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS) is 0.
The gl here is created by glCore.createContext(this.view, this._contextOptions);, content of which is

var createContext = function(canvas, options)
{
    var gl = canvas.getContext('webgl', options) || 
         canvas.getContext('experimental-webgl', options);
    if (!gl)
    {
        // fail, not able to get a context
        throw new Error('This browser does not support webGL. Try using the canvas renderer');
    }
    return gl;
};

I don't find any problem of the gl context creation.

So I guess the reason of the problem is that the texture units of this canvas is used by the former gl context and there is none left for the second gl context, so gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS) gets 0.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gigamesh picture gigamesh  路  3Comments

gaccob picture gaccob  路  3Comments

sntiagomoreno picture sntiagomoreno  路  3Comments

Makio64 picture Makio64  路  3Comments

lucap86 picture lucap86  路  3Comments