Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getExtension of undefined when instantiating WebglFilterBackend #5466

Closed
yannickguillemot opened this issue Jan 7, 2019 · 5 comments · Fixed by #5478
Closed

getExtension of undefined when instantiating WebglFilterBackend #5466

yannickguillemot opened this issue Jan 7, 2019 · 5 comments · Fixed by #5478

Comments

@yannickguillemot
Copy link

I am working on a large scale application where we manually initialize the filter backend as the fabric canvas object is also initialized.

My module interacting with FabricJS is tested with jest and jsdom. In this scenario only, I get an error in fabric's code (this.captureGPUInfo):

TypeError: Cannot read property 'getExtension' of undefined
      17198 |       }
      17199 |       var gl = this.gl;
    > 17200 |       var ext = gl.getExtension('WEBGL_debug_renderer_info');
            |                    ^

More specifically here's where the code block we are interested in:

  /**
   * WebGL filter backend.
   */
  function WebglFilterBackend(options) {
    if (options && options.tileSize) {
      this.tileSize = options.tileSize;
    }
    this.setupGLContext(this.tileSize, this.tileSize);
    this.captureGPUInfo();
  };

this.setupGLContext ( and more specifically this.createWebGLCanvas) assigns a value to this.gl if the canvas element has a webgl or a experimental-webgl context. Without checking if it's truthy, this.captureGPUInfo then tries to access it. It seems like a jsdom canvas has none of these contexts available and makes the tests break.

Here's how I initiate FabricJS: https://jsfiddle.net/YannGuillemot/tq9mz284/

I have been able to get around that by checking if we were running the code in a testing environment. Any suggestions on how to better handle this or would we have to check for node every time?

@asturur
Copy link
Member

asturur commented Jan 7, 2019

i guess fabric could early exit if this.gl is falsy?

@yannickguillemot
Copy link
Author

I looked into the captureGPUInfo method and checking for gl before calling gl.getParameter would fix my use case at least.

var renderer = gl && gl.getParameter(ext.UNMASKED_RENDERER_WEBGL);
var vendor = gl && gl.getParameter(ext.UNMASKED_VENDOR_WEBGL);

or even

if (ext && gl) {
        var renderer = gl.getParameter(ext.UNMASKED_RENDERER_WEBGL);
        var vendor = gl.getParameter(ext.UNMASKED_VENDOR_WEBGL);
        ...

I am not sure if it impacts other parts of the codebase.

@yannickguillemot
Copy link
Author

Actually, just var ext = gl && gl.getExtension('WEBGL_debug_renderer_info'); should do the trick.

@asturur
Copy link
Member

asturur commented Jan 8, 2019

i should early exit from all the function that use a glContext since that is not supported in node.
Please feel free to open a pr to do that if you have time.
i prefere a more visible

if (!gl) {
  return;
}

as early as possible

@yannickguillemot
Copy link
Author

I am sorry, I just tuned back into this issue. Glad to see you got a PR merged! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants