2020-11-25 00:25

What is the proper way to destroy glslCanvas when not used anymore?

Hello Patricio

Cool thing you did with glslCanvas. Going to use it for React components and the specifics there is that components can be mounted / unmounted often. So destroying component properly without memory leak is crucial.

SInce I do not see any explicit methods for destroying glslCanvas I want to ask: What is the proper way to do this?


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • weixin_39669133 weixin_39669133 5月前

    Hi thanks! I have no idea... but a quick search bring this up: - http://stackoverflow.com/questions/23598471/how-do-i-clean-up-and-unload-a-webgl-canvas-context-from-gpu-after-use - https://github.com/KhronosGroup/WebGLDeveloperTools/blob/master/src/debug/webgl-debug.js

    I will appreciate any PR concerning this issue : )

    点赞 评论 复制链接分享
  • weixin_39669133 weixin_39669133 5月前

    Wait! I did ad this: https://github.com/patriciogonzalezvivo/glslCanvas/blob/master/src/GlslCanvas.js#L166-L180

    It will delete textures and shader program... but I'm uncertain if it's the best way to delete the WebGL context. Suddenly = null doesn't seems very elegant : )

    点赞 评论 复制链接分享
  • weixin_39524147 weixin_39524147 5月前

    This is a proper way to clean objects in JS =) There is a delete keyword but it have weird behavior. Cool thanks. Will try this and make PR if there is a potential improvement.

    点赞 评论 复制链接分享
  • weixin_39669133 weixin_39669133 5月前

    thanks! I'm curious to see what you build with it. : )

    点赞 评论 复制链接分享
  • weixin_39828102 weixin_39828102 5月前

    This doesn't work for me when using a texture. I receive the following error javascript error:

    Uncaught TypeError: Failed to execute 'deleteTexture' on 'WebGLRenderingContext': parameter 1 is not of type 'WebGLTexture'.
        at GlslCanvas.destroy (mixin.js:56)
    点赞 评论 复制链接分享