Capture context lost error

Hi, I wonder if there is a way to control if the viewer has lost its context? My first thought was to catch the canvas element from the iframe and then do canvas.addEventListener('webglcontextlost', function (e) { console.log (e); }, false);
But I can’t access the Iframe child because of CORS policy.
My second idea was to capture the warning message “webgl context lost” when it appears. But that message is returned from the “vendors” script which isn’t loaded in my app and then I cannot reach that eighter. My last idea was to check if the viewer stops when then the web-gl context get lost by using the api function api.addEventListener('viewstop') but this event doesn’t fire even if the viewer stops rendering. So I have no idea how I can capture the context lost error in the code.

Hi,

We do not fire any event in this case.
We could though I’m not sure what you could do with it ?

Hi Paul.
I’m developing a AngularJs app to view different sketchfab models. If I’m loading about 7-9 models and start the viewers, this error can appear within a few hours. If it appears I want to restart the browser and reload the page. I can do that by running a test with Protractor. If I can change a state in my viewer app when the error appears I can capture it in the test and restart the browser.

why not just hard code a time cycle to reload every few hours , regardless of if an error occurred or not.

That is one solution but I want the app to reload directly after the error occurred, otherwise the app will be unusable until the time the page is reloaded.

@paul_sketch

I found today that the error might be coused by a memory leak. I was calling getCameraLookAt() inside onTick() (almost in the same manner you do here) an then the memory allocation grew very fast when I ran a memory test with protractor:
test_wCalling

Then I removed getCameraLookAt() from onTick() and the memory allocation stoped growing:

test_noCalling

In this example I’m viewing 7 models.
This might be the reason why the context lost error appeared, because of a memory leak inside a continuously repeating function but I’m not 100% sure yet. I need to do more tests.

//Erik

yeah browser api’s have no means to do memory management currently. It would be so nice to be able to trigger a garbage collection cycle manually :wink: Im not sure if the sketchfab devs can rework the internals of this function to avoid allocation, it is possible sometimes , but other times not. A sketchfab dev will have to respond on it.

Ive seen this issue with using many textures at runtime… the memory for loaded images is not cleared. Even if you remove them from the DOM. So applications that run for a long time doing texture injection will also suffer memory issues, more so on mobile devices.

chat soon

We recently fixed some memory leaks, but I’m not sure if this was the same one, @paul_sketch