LibGDX: How to reliably determine if the opengl context is lost?

Is there a callback to receive notification after the openGL context is lost?

I tried ApplicationListener / Game.resume (), but (on Android) there are cases where resume () is called, although the context has not been lost. As in some other cases, when the context was really lost, but resume () was not called at all.

What is the correct way to reliably determine if the openGL context is lost in libGDX?

+5
source share
2 answers

There is no easy solution for an application with controlled and unmanaged / dynamic textures. The article explains why you cannot get a trigger. I would recommend using AssetManager so that you can update your assets in the ApplicationListener resume method. You should visit and read both links.

0
source

It is very unlikely that you will have a loss of context in the first place. See this post for a more detailed explanation. But even if you have a loss in context (which will only happen on very old Android devices running Android 2.x), libGDX will take care of this and restore resources for you. You do not need to do anything for this.

Most likely, you somehow β€œthink” that you have a loss of context, but in fact you have a different problem. For example, the most common reason people think they have a loss of context is when they use static resources. For instance. using singleton pattern with lazy initialization.

Of course, without seeing any code, this is just a guess.

0
source

All Articles