Trying to get a handle on WebGL context lost

In real circumstances, the browser is responsible for raising the lost then restore event when the context has been restored and the app can recreate the webgl objects. Maybe sometimes you have to refresh explicitely the page because the browser can’t restore the context for some reason…

See HandlingContextLost - WebGL Public Wiki

1 Like

ok, I have some ideas for additional testing, I will close this again for now :smiley:

1 Like

Testing this in alpha.36, I find that some gltfs fail to reappear after context restore. In this example the boom box comes back but the grassy river scene does not: https://playground.babylonjs.com/#WGZLGJ#3432

Also I still get things like Error: Unable to create vertex buffer, Error: Unable to create uniform buffer occasionally when simulating context lost, and then the restore does not bring anything back. Seems to be related to timing of loading models, this playground produces it pretty reliably for me https://playground.babylonjs.com/#WGZLGJ#3433 .

2 Likes

The first one may be related to using the mesh_opt extension, as there is this warning in the console “Warning: meshopt_decoder is using experimental SIMD support”.

Regarding the second one, there are some limits to restoring everything automatically: if the context lost occurs during a load operation, we are probably in an unstable state and the restoration won’t/can’t work.

1 Like

Yeah that does seem to be related, reverting to an unoptimized version of one of the models this is giving me trouble with does fix it. However, not all optimized models fail. Here’s one that restores: https://playground.babylonjs.com/#WGZLGJ#3440

Ok, the difference is that you use .ktx2 textures in the file that does not work and this format is not handled (yet) by the context restore code.

This PR will fix the problem:

1 Like

In the end I concluded that all instanced where the context was lost in practice it was an unrecoverable situation because there was no webglcontextrestored event fired from webgl itself. So nothing Babylon could do about that.

And now we wait for better web tech like WebGPU!