Fix Android backend cleanup (#3681)

This commit is contained in:
Adrian Cojocaru
2025-08-25 22:24:06 +03:00
committed by GitHub
parent 12a303aa3c
commit 3cef33215c
3 changed files with 20 additions and 4 deletions

View File

@@ -37,7 +37,13 @@ AndroidGLRendererBackend::AndroidGLRendererBackend()
: gl::RendererBackend(gfx::ContextMode::Unique),
mbgl::gfx::Renderable({64, 64}, std::make_unique<AndroidGLRenderableResource>(*this)) {}
AndroidGLRendererBackend::~AndroidGLRendererBackend() = default;
AndroidGLRendererBackend::~AndroidGLRendererBackend() {
#ifndef NDEBUG
if (context && static_cast<gl::Context&>(*context).getCleanupOnDestruction()) {
assert(eglGetCurrentContext() != EGL_NO_CONTEXT);
}
#endif
}
gl::ProcAddress AndroidGLRendererBackend::getExtensionFunctionPointer(const char* name) {
assert(gfx::BackendScope::exists());

View File

@@ -196,6 +196,11 @@ void MapRenderer::requestSnapshot(SnapshotCallback callback) {
void MapRenderer::resetRenderer() {
renderer.reset();
#if MLN_RENDER_BACKEND_OPENGL
// GL requires the context managed by the java surface for cleanup
// Vulkan resources can be released on any thread (finalizer in this case)
backend.reset();
#endif
swapBehaviorFlush = false;
}

View File

@@ -272,9 +272,7 @@ public class MapLibreGLSurfaceView extends MapLibreSurfaceView {
private void destroySurfaceImp() {
if (mEglSurface != null && mEglSurface != EGL10.EGL_NO_SURFACE) {
mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE,
EGL10.EGL_NO_SURFACE,
EGL10.EGL_NO_CONTEXT);
mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, mEglContext);
MapLibreGLSurfaceView view = mGLSurfaceViewWeakRef.get();
if (view != null) {
view.eglWindowSurfaceFactory.destroySurface(mEgl, mEglDisplay, mEglSurface);
@@ -284,6 +282,13 @@ public class MapLibreGLSurfaceView extends MapLibreSurfaceView {
}
public void finish() {
if (mEglDisplay != null) {
mEgl.eglMakeCurrent(mEglDisplay,
EGL10.EGL_NO_SURFACE,
EGL10.EGL_NO_SURFACE,
EGL10.EGL_NO_CONTEXT);
}
if (mEglContext != null) {
MapLibreGLSurfaceView view = mGLSurfaceViewWeakRef.get();
if (view != null) {