CONTEXT_LOSE_WEBGL: loseContext: context lose in Chrome after some time

webglrenderer

#1

I am loading a 3D model using three.js. After some random amount of time, This error appears in the console and 3D model disappears. I tried handling it using restore context but doesn’t resolve anything.

renderer.domElement.addEventListener('webglcontextlost', function(e) {
        setTimeout(renderer.forceContextRestore, 100);
});

Also, The 3D model appears to be there but I cannot see it. But all the clicks on model works fine even when it’s not visible.


#2

Your event listener is wrong. First, you should listen to the webglcontextrestored event. Second, you should not force a context restore in the event listener. It’s the responsibility of your app to ensure that the correct state for rendering is restored in this handler like mentioned in the following github issue:


#3

But when I use
renderer.forceContextLoss();
This event fires up alright. Also, I know three.js should do this by default, But I guess it’s not happening in this case as my 3D model seems to disappear.


#4

Simulating a context loss via WebGLRenderer.forceContextLoss() is just for testing purposes.

As stated in the github issue, three.js can’t restore all application specific logic.


#5

As I mentioned earlier, my 3D model clicks works fine but model is not visible. Why do you think that is? Is it so that the context is restored but there is something like lighting which is not there?


#7

Can you share a link to your application? Without reproducing the problem it’s hard to tell what’s going wrong.


#10

The application runs on Intranet. However, I am sharing the console output. @mrdoob


#11

Sry, but the console output is not helpful in this case.


#12

I understand that but it’s not possible for me to share URL. But let’s say if the model disappears and there is a message as shown in console output regarding “webgl context lost” but all the raycaster clicks are working fine and I cannot see the model, Can you make a guess that what could it be? May be in which direction I should look to fix this issue?


#13

You should start commenting-out parts of code bit by bit until your error no longer occurs. Ask yourself common debugging questions: “Does it work with a simple cube?”, “Does it happen after a specific event?”, “Does it happen in all brorwsers, or just Chrome?”.

Really hard to tell without a minimal example. You could go to https://jsfiddle.net/ and re-create the issue with the minimal amount of code necessary so maybe others can help you look into it.


#14

Actually, everything works fine. There is a 3D model loaded. But model goes away randomly over time in Chrome browser and that too on specific machines. I have compared the configuration of those machines with the machines where the error doesn’t come at all. The only difference is the graphics card memory. I cannot reproduce this error at will as this happens randomly let’s say in 20-25 mins


#15

If it’s the GPU memory, try loading smaller textures and a simpler 3D model. But like Mugen87 and I have said, it’s impossible to know without a minimal example. JSFiddle is a great way to show your bugs to others.