Elius94 / react-photo-sphere-viewer

Photosphere Viewer for React.JS
MIT License
70 stars 21 forks source link

[Bug]: Too many active WebGL contexts. Oldest context will be lost. #66

Open JarrenMorris opened 1 day ago

JarrenMorris commented 1 day ago

What happened?

WebGL context was not being garbage collected as new viewer values were created.

What should have happened?

viewer.destroy() should handle calling these:

viewer.renderer.renderer.dispose()
viewer.renderer.renderer.forceContextLoss()

but it is not.

Solution

To get the cleanup to work properly, I had to access the private renderer in the class.

useEffect(() => {
    return () => {
        if (viewer && viewer.container && viewer.container.parentNode) {
            ;(viewer.renderer as unknown as any)?.renderer?.dispose()
            ;(viewer.renderer as unknown as any)?.renderer?.forceContextLoss()
            viewer.destroy()
        }
    }
}, [viewer])

Code

useEffect(() => {
    return () => {
        if (viewer && viewer.container && viewer.container.parentNode) {
            viewer.destroy()
        }
    }
}, [viewer])

Sandbox Link

No response

Library Version

latest

What operating system are you using?

macOS

What browser are you using?

Chrome

Logs

Too many active WebGL contexts. Oldest context will be lost.

Interest to fix the bug

Elius94 commented 1 day ago

Hey! Please, make me a sandbox :)