Sunday, May 11, 2014

WebGL in Chrome 36 Linux is Not Working


I knew this would bite me eventually.

I am using an older version of Three.js (r52) for 3D Game Programming for Kids. It was a very solid release and it worked well with other libraries available at the time that I wrote the book (like Physijs). I need to stick with that older version of Three.js because it is prohibitively hard to test the examples—and more importantly the steps I walk kids through—with every new version of Three.js and the associated libraries.

Unfortunately, not tracking changes to Three.js means that I do not get the changes that track changes to underlying browser technology. While testing this stuff recently, I noticed something worrisome in the forthcoming Chrome 36. WebGL no longer works. In the JavaScript console, I am seeing the following errors:
THREE.WebGLRenderer 52 Three.js:15545
Error creating WebGL context. Three.js:22347
Uncaught TypeError: Cannot read property 'getExtension' of null 
Looking closer at that error, I see that it is originating on line that attempts to access the WebGL context:
 function initGL () {
  try {
   if ( ! ( _gl = _canvas.getContext( 'experimental-webgl', { /* ... */ } ) ) ) {
    throw 'Error creating WebGL context.';
   }
  } catch ( error ) {
   console.error( error );
  }
    // ...
  }
I am going to go out on a limb to guess that Chrome 36 has dropped the experimental- prefix to that context.

Unfortunately, that is not the answer. At least not all of it. With the following, I still get the same error:
       function initGL () {
                try {  
                        var attributes = { alpha: _alpha,
                                premultipliedAlpha: _premultipliedAlpha,
                                antialias: _antialias,
                                stencil: _stencil,
                                preserveDrawingBuffer: _preserveDrawingBuffer } ;
                        _gl = _canvas.getContext( 'webgl', attributes) || _canvas.getContext( 'experimental-webgl', attributes );
                        if ( _gl === null ) {
                                throw 'Error creating WebGL context.';
                        }
                } catch ( error ) {
                        console.error( error );
                }
WebGL is definitely working in Chrome 36 (Linux). I can see the spinny cube on http://get.webgl.org/... except I'm wrong — it's not working there after all. Such are the hazards of running Chrome Beta and Chrome Unstable side-by-side. I must have originally checked WebGL support in Chrome Beta (35), but thought I was looking at Chrome Unstable (36). Now I that look again, I see:
Hmm. While your browser seems to support WebGL, it is disabled or unavailable. If possible, please ensure that you are running the latest drivers for your video card.

For more help, please click this link.
Following the instructions in that link, I checkout chrome://gpu/ to find that WebGL is unavailable in my Chrome 36 (it works fine in 35):



I can find no explanation for why Chrome might think this. If I check chrome://settings, I find that hardware acceleration is enabled


Well, that does not seem like an old version of Three.js kind of problem. For all I know, this is just an unstable Chrome Linux problem that will be sorted out shortly. I may dig into this a bit more and possibly submit a bug report (it seems like some already exist). Still, I am relieved that I can hold off on changes to the Three.js library used to support the book. If I am very lucky, I can hold off on that until the next edition. Fingers crossed!



Day #60

2 comments:

  1. I picked today to start playing with Three.js and also see this exact behaviour on the latest (release) version of Chrome on OSX... Since I just started out it's also the latest three.js from githuib, btw!

    ReplyDelete
  2. I have a website running Three.js r58 for a year and I just noticed this. However my chrome:// gpu/ page shows everything enabled. Any ideas on how to fix this ?

    ReplyDelete