patriciogonzalezvivo / glslCanvas

Simple tool to load GLSL shaders on HTML Canvas using WebGL
http://patriciogonzalezvivo.github.io/glslCanvas/
MIT License
1.99k stars 183 forks source link

destroy instance is incomplete? #50

Closed digitaljohn closed 5 years ago

digitaljohn commented 5 years ago

I'm using glslCanvas within a react app and am failing to cleanly destroy the instance. It appears the render loop does not get aborted so causes an error after the destruction?

My hook looks like this:

// Spawn the glsl canvas
  useEffect(() => {
    if (!webGlSupported && GlslCanvas) return;
    sandbox.current = new GlslCanvas(canvas.current);
    return () => {
      sandbox.current.pause();
      sandbox.current.destroy();
    };
  }, [webGlSupported]);

This causes an error:

Uncaught TypeError: Cannot read property 'canvas' of null
    at GlslCanvas.resize (GlslCanvas.es.js:1394)
    at RenderLoop (GlslCanvas.es.js:1084)

Related: #8