You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are encountering an issue when we have multiple plots with GL layers. When there are more then 16 WebGL contexts in use, the oldests will be "lost", showing a frowny. The console will also show "WARNING: Too many active WebGL contexts. Oldest context will be lost."
The browser limits the number of contexts to 16 per "site instance" by default and in our case it is not practical to change the browser options. Each GL layer (possibly each series, depending on the zlevel option) currently requires its own context.
I've been experimenting a bit and found that it is possible to use only one context and share it with all plots and layers. Details are below.
I've seen no issues with it so far, but I'm not familiar enough with this library. I'm sure the code has to be improved in places and checks have to be added for each (interface) function that uses the renderer. I'm not sure if there are cases where needed information is lost when recreating the renderer.
Hopefully you can have a look and see if you can incorporate this or something similar in a future version of the library. It would help a lot.
webgl_context_lost.html: Example HTML to easily create varying number of plots with varying number of GL layers.
webgl_context_lost_LayerGL.patch: Git patch for LayerGL.js changes
webgl_context_lost_release_2.0.7.patch: Patch for release 2.0.7
webgl_context_lost_release_2.0.7_no_sharing.patch: Patch for release 2.0.7 without the shared renderer/context
My approach is to create a separate canvas element from the one of the renderer. After the renderer is done drawing, the result is copied to the separate canvas which is used for displaying.
Additionally, when trying to redraw, I check to see if the context is lost and, if so, simply reinstantiate the renderer.
In principle this also works without having the shared renderer/context, but the performance impact can be quite significant if, for example, you have a plot with more than 16 GL layers. In that case the renderer is recreated many times for each layer. You notice the difference clearly when using the attached example files and creating 1 plot with 17 layers. Toggling series and resizing is noticably affected.
The text was updated successfully, but these errors were encountered:
To test, I used one tab with the old library and duplicated that tab and then used the patched library in the duplicated tab. By duplicating tabs you ensure they used the same pool of WebGL contexts. Then, in the second "patched" tab make sure you have a plot with a GL layer and in the first "unpatched" tab create at least 16 GL layers. That should invalidate the shared one that is used in the second tab. Toggling layers or resizing plots in the second tab should then result in reallocation of the shared context.
Added pull-request #440 with the fix that I've come up with.
I've used the tests in the test directory to see what the impact is. I've found a couple of issues with my original patch that I've fixed in the PR. Other than that it seems to work quite well.
The only issue that I don't think I can fix myself a.t.m. is that some plots use certain effects or textures that seem to get lost when recreating the renderer. As mentioned in the PR, a typical example is in test/surface-metal.html. Still, I'd say it's already a significant improvement over plots completely not working when the context is lost.
We are encountering an issue when we have multiple plots with GL layers. When there are more then 16 WebGL contexts in use, the oldests will be "lost", showing a frowny. The console will also show "WARNING: Too many active WebGL contexts. Oldest context will be lost."
The browser limits the number of contexts to 16 per "site instance" by default and in our case it is not practical to change the browser options. Each GL layer (possibly each series, depending on the zlevel option) currently requires its own context.
I've been experimenting a bit and found that it is possible to use only one context and share it with all plots and layers. Details are below.
I've seen no issues with it so far, but I'm not familiar enough with this library. I'm sure the code has to be improved in places and checks have to be added for each (interface) function that uses the renderer. I'm not sure if there are cases where needed information is lost when recreating the renderer.
Hopefully you can have a look and see if you can incorporate this or something similar in a future version of the library. It would help a lot.
Details
Example files: webgl_context_lost.zip
My approach is to create a separate canvas element from the one of the renderer. After the renderer is done drawing, the result is copied to the separate canvas which is used for displaying.
Additionally, when trying to redraw, I check to see if the context is lost and, if so, simply reinstantiate the renderer.
In principle this also works without having the shared renderer/context, but the performance impact can be quite significant if, for example, you have a plot with more than 16 GL layers. In that case the renderer is recreated many times for each layer. You notice the difference clearly when using the attached example files and creating 1 plot with 17 layers. Toggling series and resizing is noticably affected.
The text was updated successfully, but these errors were encountered: