CANDELbio / mantis-viewer

Electron-based multiplexed imaging viewer
Apache License 2.0
22 stars 7 forks source link

Some graphics and sprites not rendering after WebGL context loss #72

Closed beixiangsiyu closed 2 years ago

beixiangsiyu commented 2 years ago

Hello!I saw your problem in pixijs forum, maybe i have the same problem as you. Can you tell me how you fix that problem? Thanks a lot!

rj3d commented 2 years ago

Hey there! I wasn't able to fully fix it to be honest. I'll let you know what I tried though.

First pass you can minimize the number of sprites, graphics, geometry, etc. objects that you are creating. Try to reuse the objects whenever possible instead of creating new ones. If you are loading textures from images, reduce the size of the images if possible. Try to avoid using geometry objects if possible as they use a lot of resources. Doing this was able to reduce the frequency of context losses for me, but did not eliminate them entirely.

I was able to recover for a little while by adding an event listener for webglcontextloss and then deleting and recreating all of the graphics and sprites objects followed by a forced rerender. This would work for a couple rounds of WebGL context losses, but eventually stoped working after multiple context losses.

My final solution was just to relaunch the application on WebGL context loss and reload the previous state. It's not an elegant solution, but it works for now. Long term I'm planning to replace PixiJS with a different WebGL library to eliminate the problems.

beixiangsiyu commented 2 years ago

Thanks a lot! Exactly, when my page get white, there isn't any error appear in my console. So I'm not sure my page get white because of webgl context loss. Did you drop an error? Did all pixi programs have this question?

rj3d commented 2 years ago

I always get an error on context loss. You could try testing by adding an event listener and then printing to console.

canvas.addEventListener('webglcontextlost', () => {
    console.log('Context lost!')
})

Not all PIXI programs have this issue. I'm not sure what causes it, but I think it only happens if you're using too many resources on the graphics card.

beixiangsiyu commented 2 years ago

Thank you very much! I'll try my best to fix this problem in my program.