# \[vtkjs\] Reload scene on lost graphic context, best practices?

**URL:** https://discourse.vtk.org/t/vtkjs-reload-scene-on-lost-graphic-context-best-practices/15789
**Category:** Support
**Tags:** vtkjs
**Created:** [July 7, 2025, 8:56am UTC](https://discourse.vtk.org/t/vtkjs-reload-scene-on-lost-graphic-context-best-practices/15789 "2025-07-07T08:56:14Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [July 7, 2025, 8:56am UTC](https://discourse.vtk.org/t/vtkjs-reload-scene-on-lost-graphic-context-best-practices/15789/1 "2025-07-07T08:56:14Z")

</div>

Hello  
Sometimes my scene gets a lost graphic context. Therefore, I shall add a reload scene button. Is there a best practice way to do this, theoretically automatic?

---

<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: [July 14, 2025, 9:46pm UTC](https://discourse.vtk.org/t/vtkjs-reload-scene-on-lost-graphic-context-best-practices/15789/2 "2025-07-14T21:46:28Z")

</div>

Hello,

I’ve never heard of “lost graphic context”. Perhaps if you give more detail of your issue the people may be able to help.

best,

PC

---

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [July 15, 2025, 8:35am UTC](https://discourse.vtk.org/t/vtkjs-reload-scene-on-lost-graphic-context-best-practices/15789/3 "2025-07-15T08:35:15Z")

</div>

In a page with graphic context like a vtk scene, sometimes the graphical buffer is overloaded with the use of other pages with more graphical context. This creates a race for resources in the system, which deletes the unused ones. Typically, everything is stored in the cached variables, so the issue is to reload the graphical context on page activation. However, this is a lengthy process that shall be avoided if the context is preserved.  
I could add an event on page reload to launch the redraw of the scene. But I need a way to check if the scene has really lost its connection to the graphical system.

EDIT: If you want to replicate, just create two scenes and load them at the same time. Try to load some big ones, so each uses most of your card. you will see “lost graphical context” in one of them.

---

<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: [August 19, 2025, 2:05pm UTC](https://discourse.vtk.org/t/vtkjs-reload-scene-on-lost-graphic-context-best-practices/15789/4 "2025-08-19T14:05:23Z")

</div>

Hello,

Sorry for the late response.

For that, in Windows, you can try `wglGetCurrentContext()`, defined in `wingdi.h`. In Linux, you can try `glXGetCurrentContext()`, defined in `GL/glx.h`. If they return NULL, the thread has lost its “connection” to the graphics system.

I hope this helps,

PC
