flekschas / regl-scatterplot

Scalable WebGL-based scatter plot library build with Regl
https://flekschas.github.io/regl-scatterplot/
MIT License
184 stars 21 forks source link

(regl) context lost #185

Open oskbor opened 4 days ago

oskbor commented 4 days ago

Hi! I have seen that some of our users are experiencing (regl) context lost errors when they leave a page idle for a while (with a regl-scatterplot in it). From some cursory research it seems this can happen for a many reasons like the GPU being used by other tabs, too many contexts open across tabs, a laptop switching GPU when plugged in/out. Is it possible for regl-scatterplot to detect and recover from this error? Or can I recover from my application somehow?

best regards Oskar

flekschas commented 4 days ago

That's a tough issue as the application cannot control when the context is lost. It can happen any time. Weirdly I've never experienced it myself but you could try to catch the context loss error and re-instantiate the scatterplot. E.g.: https://stackoverflow.com/a/28170868

To catch a context loss event is easy. Just listen for the event on the renderer's canvas element as exemplified https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/contextlost_event#example