How to clear a gl context

Hi everyone,
I’ve met a problem with the webgl context lost, my project has several components, each components have different genericRenderWindows, when switching from one to another, I will need to clear the old ones and create new ones, what I did is to get the openglRenderWindow from each genericRenderWindow and did ‘genericRenderWindow.setContainer(null)’, ‘openglRenderWindow.delete()’, and delete the container dom for each one.

There was no problem when the windows are not too many no matter how fast and how many times I switch the components, but in one situation that the first component has 10 window and the next has 7, the context lost will be shown. The maximum context number for my browser is 16, I tried to clear the old ones and create the new ones after a timeout of 2-5 seconds to test if it works, but the context lost will still show.

Another situation is when some actors are shown when loaded, the context lost will appear, but if I set their visibility to false the context lost will not show.

How should I clear it properly to avoid the context lost? The windows are for different usages so they can not be reused.


I would recommend either using many vtkRenderers in a single vtkRenderWindow, or reusing the existin vtkRenderWindows when switching. AFAIK you really won’t know when the browser has GC’ed the canvas context in order for you to begin creating a new one and remain under the limit.

Thank you Forrest, I will consider the many renderers, it’s not the same window and can not be reused