Android device slow unless returning from background?


#1

We use SDL2 in our framework, and I’ve received another report of something I’ve heard from users before:

I’m having an odd issue with Android performance (all recent releases)
When I start performance is pretty choppy, even though average fps is 60
but if I minimize and reopen the app, the performance is flawless

Has anyone encountered an issue like this before?

Thanks!


#2

Hi again,

This has been difficult to diagnose, but I believe the issue might be caused by not calling SDL_GL_MakeCurrent initially:

Before

context = SDL_GL_CreateContext (sdlWindow);

if (context) {

	if (flags & WINDOW_FLAG_VSYNC) {
		SDL_GL_SetSwapInterval (1);
	} else {
		SDL_GL_SetSwapInterval (0);
	}

	...

After

context = SDL_GL_CreateContext (sdlWindow);

if (context && SDL_GL_MakeCurrent (sdlWindow, context)) {

	if (flags & WINDOW_FLAG_VSYNC) {
		SDL_GL_SetSwapInterval (1);
	} else {
		SDL_GL_SetSwapInterval (0);
	}

	...

I’m not sure if this is documented, but I believe that suspending and resuming on Android will call SDL_GL_MakeCurrent automatically, but using GL without setting the context as current may be the cause of the unsteadiness (even though FPS reports the same).

EDIT: Nevermind, I accidentally used SDL_GL_MakeCurrent incorrectly:

if (context && SDL_GL_MakeCurrent (sdlWindow, context)) {

should have been

if (context && SDL_GL_MakeCurrent (sdlWindow, context) == 0) {

Our engine fell back to Cairo for software rendering, so software rendering on Cairo doesn’t look jerky, so it’s something specific to GL, but only until the application is sent to the background.

If anyone has seen something similar, let me know. It’s a bit hard to see until you realize its there the first time