Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for restoring upon context loss #74

Open
hansagames opened this issue Jun 2, 2020 · 11 comments
Open

Add support for restoring upon context loss #74

hansagames opened this issue Jun 2, 2020 · 11 comments
Labels
enhancement New feature or request

Comments

@hansagames
Copy link

Was starting to think around context lose restore, how to better add support directly or as plugin to gl https://www.khronos.org/webgl/wiki/HandlingContextLost

Its way simpler to add support inside framework as references to textures, shaders are needed to restore them on lose event, but maybe you have some thought already on this topic ?

@gordonnl
Copy link
Contributor

gordonnl commented Jun 2, 2020

hey thanks again.

Yeah I've had this on the todo list for a couple of years, but I'm not really sure how useful it actually is. I have to do an inspection to see what would be entailed, and then consider it based on how it would affect the framework vs the very small percentage of use cases (in the worst case scenario, user would have to refresh).

Are there any major use-cases (like VR?) you know of that I'm missing, that absolutely would need it?

In one of your MDN links for the resource release issue, they actually suggest triggering WEBGL_lose_context.loseContext() to release the context and its resources - which is an interesting idea I hadn't thought of. I wonder if a developer does use that to free resources, the framework automatically re-creating and binding everything would actually be the opposite of what they want.

@hansagames
Copy link
Author

So there are 2 main use case for this, firstly mobile devices especially android tend to lose context quite often, usually it happens du to user going to other gpu based or when resources are running out, phone can decide to free context, when this happens user will need to refresh page e.c

Second use case is if device have multiple cards and it starts to switch between them, in this case webgl will trigger context lose as well

Personally I have faced mobile uses case about multiple cards haven't heard really

@hansagames
Copy link
Author

But yes VR is having this as well

@Anemolo
Copy link

Anemolo commented Jul 22, 2020

I would say this is a must have for the mobile devices, I don't think having to refresh is good. And, if it's worth something, every other dev using ogl that I've talked to had to implement this

Would love to contribute on this if needed! If bundle size is a big worry, I think even as part of the /extras would be great and solve all concerns(not sure how that would look like).

@gordonnl
Copy link
Contributor

Ah interesting! I haven't come across any implementations yet, so that's news to me. I'm surprised I've never experienced this myself.

It would be great to get an idea of what exactly would need to be included. I unfortunately don't have the time to dedicate at the moment.

I would assume that basically everything would need to be stored somewhere - eg no more calls direct to the gl context. Currently OGL doesn't keep track of everything you create. In my quick assumptions, it would seem to me that a pretty deep re-structure would be necessary to store everything a dev does with the library, in order for it to automatically re-create everything.

@hansagames
Copy link
Author

Yes you need reference to most of parts like geometry and textures also need to store information needed to recreate them.
And of course gl references need to be updated, I have implemented naive version, I ma ready to share more if needed

@terkelg
Copy link
Contributor

terkelg commented Sep 30, 2020

I don't know which parts that has to be stored but I wonder if Proxy could be a solution. Simplicity and minimal abstractions are the main features of OGL. I'm worried adding a layer of abstraction to the gl context will result in quite a few wrapper methods getting added, increasing complexity and in the end making the library harder to maintain over time.

@hansagames
Copy link
Author

You need to have access to all meshe / textures/ materials/ geometry so need some central point where you have access to all of these

@hansagames
Copy link
Author

I created concept of engine that is central point and wrapped all ogl classes in custom creator functions in order to have references when they are created

@eXponenta
Copy link
Contributor

eXponenta commented Dec 25, 2020

This is interesting, but not needed, and shifts a user problem to framework side.

We has a huge WebGL application, and by statistics a tab crash by ram/vram issues is more frequently that context losting.
There are case when user a switch browser by any reason and it will cached (iOS), sometimes Safari restore a page with broken context.
But any case a page data should be invalidated too, and easiest way is forcing reload page or rerun app, that restoring a state.

@hansagames
Copy link
Author

@eXponenta this is huge thing on newer versions of androids, have logs for these cases same happens on iOS 14 as well, befere 14 it was almost not visisble on iOS

@gordonnl gordonnl added the enhancement New feature or request label Mar 12, 2021
@gordonnl gordonnl changed the title Handling context lost Add support for restoring upon context loss Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants