Jump to content

"gl.disable is not a function" error in Chrome/FireFox


Recommended Posts

Hi all.

I'm getting the following error when trying to create a Pixi renderer using autoDetectRenderer in Chrome and Firefox: 

gl.disable is not a function 

at WebGLRenderer._initContext
at new WebGLRenderer
at Object.module.exports.Object.assign.autoDetectRenderer

I'm using Pixi as part of a much larger, complex framework and haven't tried taking the whole thing apart to see what's causing the problem yet; I was hoping that there might be an easy Pixi-related solution before I get to that...

From having a poke around in the Pixi source code I can make the error go away by adding a small tweak:

	 * Creates the gl context.
	 * @private
	WebGLRenderer.prototype._createContext = function () {
	    var gl = this.view.getContext('webgl', this._contextOptions) || this.view.getContext('experimental-webgl', this._contextOptions);
	    this.gl = gl;
		//  *** adding the following line makes the error go away ***

	    if (!gl.disable) this.gl = this.gl.original;

		//  *********************************************************
	    if (!gl)
	        // fail, not able to get a context
	        throw new Error('This browser does not support webGL. Try using the canvas renderer');
	    this.glContextId = WebGLRenderer.glContextId++;
	    gl.id = this.glContextId;
	    gl.renderer = this;

While this works, I'm not entirely sure why and obviously I'd rather not rely on hacked-around code in production.

So: is there an obvious/known reason this is happening that I can fix? Or, alternatively, will using the above fix break anything important?

Unfortunately I can't share a link because the project is pre-alpha still; I might be able to strip out enough to make a useful demo page but it'd be a big undertaking - I'm crossing my fingers and hoping there's something quick and obvious I can fix!

Any help much appreciated.



Link to comment
Share on other sites

Aha, thanks. There is another canvas element on the page (hidden, used for measuring text widths). So is this a problem with the specific canvas element that Pixi is using to draw (and maybe something else is trying to use), or just that there's already another canvas somewhere on the page with a 2d context?

Thanks for your help!

Link to comment
Share on other sites

The weird thing is that getContext isn't returning null, as I'd expect if a 2D context was already requested or the browser was incompatible. When Pixi calls 

this.view.getContext('webgl', this._contextOptions) || this.view.getContext('experimental-webgl', this._contextOptions);

the result is this:

	_qid: 5
	canvas: canvas
	frame: Array[0]
	id: 0
	original: WebGLRenderingContext
	renderer: WebGLRenderer

... the WebGL rendering context is there, but it's assigned to the "original" property of the returned object, rather than being the returned object itself. It's usable, and will render as expected if you point Pixi to it manually - that's why my hack posted above does let the app render using WebGL as expected.

After plenty of googling I can't find any info on what this returned object might be - it seems getContent should return either a context or null, not some weird in-between thing.

Any other suggestions/thoughts? Or do you think this'll just have to be something I live with? It works fine in IE and Safari (Win) so I'm wondering if it's some kind of browser rendering bug?


Link to comment
Share on other sites

I think you're right that Chrome and Firefox can reasonably be expected to return null rather than a non-standard object, that sounds bizarre. So, that leads me to wonder if you might have a polyfill for the canvas that might be buggy and causing the issue described, it's a long shot in the dark though...

Link to comment
Share on other sites

8 hours ago, chg said:

you might have a polyfill for the canvas that might be buggy and causing the issue described, it's a long shot in the dark though...

Nothing as far as I'm aware. I've tried letting Pixi create the canvas as usual, and even manually creating a canvas element and attaching it to document.body, with the same result.

Weird weird.

Oh well. Thanks for the suggestions everyone, much appreciated. I'll keep going - will report back if I ever find out what it is!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...