SDL_EGL_SwapBuffers crash

im getting a rare crash i cannot reproduce when calling

SDL_GL_SwapWindow(window);

in android sdl2.0.9

does any one know whats the issue?

at SDL_elg.c in this code the error is returned:

int
SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface)
{
    if (!_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, egl_surface)) {
        return SDL_EGL_SetError("unable to show color buffer in an OS-native window", "eglSwapBuffers");
    }
    return 0;
}

this is the init flow:

if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS) == 0)
{
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);

	window = SDL_CreateWindow("game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL);

	isRunning = true;

	if (!window)
	{
		SDL_Log("Error creating window: %s", SDL_GetError());
		isRunning = false;
		return;
	}

	glcontext = SDL_GL_CreateContext(window);
	if (!glcontext)
	{
		std::cerr << "Error creating GL context: " << SDL_GetError() << std::endl;
		isRunning = false;
		return;
	}

	SDL_GL_SetSwapInterval(1);

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);
}

1m

Try to use the latest SDL source code (https://hg.libsdl.org/SDL), there are lot of thread synchronization issues fixed for Android.

Create window and renderer as soon as the app starts.
Check that you get a valid window and renderer.
Start also to poll events quickly and don’t use the gl context or SDL renderer beetween the events SDL_APP_WILLENTERBACKGROUND and SDL_APP_DIDENTERFOREGROUND.

thank you, i added some gl context checks and uploaded an update, if it will not solve the issue i will try to update sdl to latest and come back with conclusions.

It seems I currently have the same problem on Android. Although this was a long time ago can you maybe share the way you fixed it if you got it to work?