acatcalledfrank Posted January 14, 2016 Share Posted January 14, 2016 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. Cheers, Tom Quote Link to comment Share on other sites More sharing options...
xerver Posted January 14, 2016 Share Posted January 14, 2016 This likely is happening because the canvas already has a 2d context created somewhere else, so we are failing trying to get a webgl context. Quote Link to comment Share on other sites More sharing options...
acatcalledfrank Posted January 14, 2016 Author Share Posted January 14, 2016 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! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted January 14, 2016 Share Posted January 14, 2016 Its the problem with the same canvas. You are using both 2d and webgl somehow Quote Link to comment Share on other sites More sharing options...
acatcalledfrank Posted January 15, 2016 Author Share Posted January 15, 2016 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? Quote Link to comment Share on other sites More sharing options...
chg Posted January 15, 2016 Share Posted January 15, 2016 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... Quote Link to comment Share on other sites More sharing options...
acatcalledfrank Posted January 15, 2016 Author Share Posted January 15, 2016 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.