greggman / virtual-webgl

Virtualize WebGL Contexts
Other
149 stars 12 forks source link

"Illegal invocation" errors on Chrome #3

Closed jjhembd closed 2 years ago

jjhembd commented 2 years ago

In Chrome on Windows, I get "Illegal invocation" errors, mostly at this line:

  // copy all WebGL constants and functions to the prototype of
  // VirtualWebGLContext
  for (let key in WebGLRenderingContext.prototype) {
    // switch (key) { // ...
        const value = WebGLRenderingContext.prototype[key]; // Illegal invocation

It's enough to break the WebGL 2 examples.

jjhembd commented 2 years ago

The problem keys are drawingBufferColorSpace and unpackColorSpace. Skipping these keys in the switch statement mostly fixes the WebGL 2 example.

      switch (key) {
        case 'canvas':
        case 'drawingBufferWidth':
        case 'drawingBufferHeight':
        case 'drawingBufferColorSpace':
        case 'unpackColorSpace':
          break;
        default: {
          let value;
          try {
            value = WebGL2RenderingContext.prototype[key];
          } catch {
            throw("Couldn't get context key " + key);
          }

The "Instanced Drawing & Vertex Array" pane is still not working, perhaps because of another Illegal invocation error in twgl related to extensions.

image

greggman commented 2 years ago

thanks for the bug report!

Updated

https://github.com/greggman/virtual-webgl/commit/66cf2b58e58ccb94963f1fb06e96290363528d62