# Why I'm having this warning, Too many active WebGL contexts. Oldest context will be lost.

**URL:** https://discourse.vtk.org/t/why-im-having-this-warning-too-many-active-webgl-contexts-oldest-context-will-be-lost/10670
**Category:** Web
**Created:** [February 14, 2023, 11:25am UTC](https://discourse.vtk.org/t/why-im-having-this-warning-too-many-active-webgl-contexts-oldest-context-will-be-lost/10670 "2023-02-14T11:25:14Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![dexter](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/dc4da7/32.png) [@dexter](https://discourse.vtk.org/u/dexter)
#### Post date: [February 14, 2023, 11:25am UTC](https://discourse.vtk.org/t/why-im-having-this-warning-too-many-active-webgl-contexts-oldest-context-will-be-lost/10670/1 "2023-02-14T11:25:14Z")

</div>

In my application, I have ResliceCursourWidget (3 genericRenderWindows) + a genericRenderWindow to display 3 **3D actors** ,  
In this application the users may have many interactions with those renderWindows, (change the Reslice center, the colorWindow, colorLevel…)

Also I’m deleting actors / renderWindows to display others depending on what the user picks

Sometimes all work just fine, but sometimes I’m getting this Warning:

`RenderWindow.js:248 WARNING: Too many active WebGL contexts. Oldest context will be lost.`

and the the ResliceCursourWidget renderWindows stop displaying actors, and they become just white …

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [February 14, 2023, 10:19pm UTC](https://discourse.vtk.org/t/why-im-having-this-warning-too-many-active-webgl-contexts-oldest-context-will-be-lost/10670/2 "2023-02-14T22:19:33Z")

</div>

Hi,

My two cents: you reached your browser’s limit. Chromium, for instance, has a limit of 16 contexts if I’m not mistaken. Other browsers likely have limits in the same order of magnitude. So, I believe you have to design your application to make use of fewer contexts (one is ideal). BTW, why do you need so many contexts? Take a look at this: [javascript - Allowing more WebGL contexts - Stack Overflow](https://stackoverflow.com/questions/59140439/allowing-more-webgl-contexts)

best,

Paulo

---

<div class="post-metadata">

### Author: ![dexter](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/dc4da7/32.png) [@dexter](https://discourse.vtk.org/u/dexter)
#### Post date: [February 15, 2023, 8:33am UTC](https://discourse.vtk.org/t/why-im-having-this-warning-too-many-active-webgl-contexts-oldest-context-will-be-lost/10670/3 "2023-02-15T08:33:48Z")

</div>

Hello Paulo,

Thank you so much for your answer, yes what you said looks convenient,  
Sorry I didn’t specify it before,

In my application I have a X number of patients, each patient has 3 files (A brain-MRI.vti, a brain-segmentation.vtk and a face-surface.vtk)

The user can choose from the list of patients a patient to display, so I charge the N patient files and I delete what is previously rendered (N-1) in order to render the new actors, (I delete the actors, mappers, widget (ResliceCursorWidget) and the OpenGLRenderWindow and the GenericRenderWindow),

I don’t know if this the right way to do it,  
 ![[video-to-gif output image]](https://discourse.vtk.org/uploads/default/original/2X/9/9cd92558474e30baee8755055fc114c0879c0c3a.gif)

PS: in the 3D view I have:  
PLANS VIEW: Plans actors + Sphere actor  
CERVEAU VIEW: Polydata actor + Sphere actor  
PEELING VIEW: 2 Poly data actors + Sphere actor

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [February 15, 2023, 11:47am UTC](https://discourse.vtk.org/t/why-im-having-this-warning-too-many-active-webgl-contexts-oldest-context-will-be-lost/10670/4 "2023-02-15T11:47:07Z")

</div>

I believe you can achieve that using a single render window. Take a look at this: [Four dipsplay Window](https://discourse.vtk.org/t/four-dipsplay-window/414)

---

<div class="post-metadata">

### Author: ![dexter](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/dc4da7/32.png) [@dexter](https://discourse.vtk.org/u/dexter)
#### Post date: [February 15, 2023, 2:01pm UTC](https://discourse.vtk.org/t/why-im-having-this-warning-too-many-active-webgl-contexts-oldest-context-will-be-lost/10670/5 "2023-02-15T14:01:28Z")

</div>

Thank you, but in the official [ResliceCursorWidget example](https://kitware.github.io/vtk-js/examples/ResliceCursorWidget.html) they have used 4 render windows, I don’t understand why they did that if it is not optimal.

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [February 15, 2023, 7:14pm UTC](https://discourse.vtk.org/t/why-im-having-this-warning-too-many-active-webgl-contexts-oldest-context-will-be-lost/10670/6 "2023-02-15T19:14:31Z")

</div>

4 is definitely less than 16 and if you were to reuse your 4 renderwindows you would not get into that issue.

---

<div class="post-metadata">

### Author: ![dexter](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/dc4da7/32.png) [@dexter](https://discourse.vtk.org/u/dexter)
#### Post date: [February 16, 2023, 8:26am UTC](https://discourse.vtk.org/t/why-im-having-this-warning-too-many-active-webgl-contexts-oldest-context-will-be-lost/10670/7 "2023-02-16T08:26:34Z")

</div>

To reuse my 4 renderWindows, what is the best approach?

- To delete the render windows and the actors, mappers, interactors… and re-create them again.
- Or to delete just actor, mapper and interactors… and keep using the same renderWindows?

Thank you for you answer

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [February 16, 2023, 3:27pm UTC](https://discourse.vtk.org/t/why-im-having-this-warning-too-many-active-webgl-contexts-oldest-context-will-be-lost/10670/8 "2023-02-16T15:27:59Z")

</div>

Just add/remove actor in those renderwindows. Keep the rest (renderwindow, renderer, interactor) the same.

---

<div class="post-metadata">

### Author: ![dexter](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/dc4da7/32.png) [@dexter](https://discourse.vtk.org/u/dexter)
#### Post date: [February 16, 2023, 3:53pm UTC](https://discourse.vtk.org/t/why-im-having-this-warning-too-many-active-webgl-contexts-oldest-context-will-be-lost/10670/9 "2023-02-16T15:53:59Z")

</div>

Thank you!
