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

Suggestion: Dispose of renderer context when canvas is destroyed? #132

Closed
UltimateForm opened this issue Jun 25, 2019 · 4 comments
Closed

Comments

@UltimateForm
Copy link

Hi again, you must be tired of me already, and I'll again annoy you on the subject of #96

I have noticed even if I only load a model at a time, I still get the warning, as you can check in this codesandbox link: https://codesandbox.io/s/react-three-fiber-context-loss-o33uq if you keep loading, unloading and reloading, you'll see that you'll end up getting the warning WARNING: Too many active WebGL contexts. Oldest context will be lost. this means the renderer is not being disposed when canvas is unmounted. Shouldn't it be? This is pretty much these stackoverflow qestions: https://stackoverflow.com/questions/21548247/clean-up-threejs-webgl-contexts and https://stackoverflow.com/questions/54323838/how-to-fully-clean-up-the-context-and-canvas-in-three-js. right now this is what i'm doing on my component:

    componentWillUnmount() {
        if(this.webGLRenderer){
            this.webGLRenderer.forceContextLoss();
            this.webGLRenderer.dispose();
            this.webGLRenderer=undefined;
        }
    }

but i have to previously get the gl from useThree() on a FunctionComponent

i'll note that on this case its not as bad as what i was experiencing on the previous issue mentioned since the contexts and renderers being lost are no longer being in use, that said I don't think its optimal having garbage renderers and contexts around.

It'd be nice if the canvas object itself could either destroy and dispose it's renderer and context once its unmounted or reuse the renderer (which may be clunkier imo)

this might also be interesting: https://threejs.org/docs/#manual/en/introduction/How-to-dispose-of-objects

@UltimateForm
Copy link
Author

i have found on your code: state.current.gl.dispose() , this by itself doesn't dipose of the context I think

@UltimateForm UltimateForm changed the title Suggestion: Dispose of renderer on when canvas is destroyed? Suggestion: Dispose of renderer context when canvas is destroyed? Jun 25, 2019
@drcmda drcmda closed this as completed in 165c5bd Jun 25, 2019
@drcmda drcmda reopened this Jun 25, 2019
@drcmda
Copy link
Member

drcmda commented Jun 25, 2019

added your code to the unmount phase, i really thought that dispose is enough :-S

@UltimateForm
Copy link
Author

UltimateForm commented Jun 25, 2019

@drcmda on a further note, i have also been noticing a memory leak, and it seems official:

mrdoob/three.js#12464

mrdoob/three.js#12447

just letting you know

@UltimateForm
Copy link
Author

thank you for the fix anyway, keep up the good work 👍

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

No branches or pull requests

2 participants