diff --git a/platform/android/MapLibreAndroid/src/vulkan/java/org/maplibre/android/maps/renderer/textureview/VulkanTextureViewRenderThread.java b/platform/android/MapLibreAndroid/src/vulkan/java/org/maplibre/android/maps/renderer/textureview/VulkanTextureViewRenderThread.java index be04ae5c6c4..3b8a0715ba0 100644 --- a/platform/android/MapLibreAndroid/src/vulkan/java/org/maplibre/android/maps/renderer/textureview/VulkanTextureViewRenderThread.java +++ b/platform/android/MapLibreAndroid/src/vulkan/java/org/maplibre/android/maps/renderer/textureview/VulkanTextureViewRenderThread.java @@ -23,7 +23,9 @@ public void run() { while (true) { Runnable event = null; - boolean initialize = false; + boolean createSurface = false; + boolean destroySurface = false; + boolean sizeChanged = false; int w = -1; int h = -1; @@ -41,20 +43,28 @@ public void run() { break; } - if (destroySurface) { - destroySurface = false; - mapRenderer.onSurfaceDestroyed(); + if (this.destroySurface) { surface = null; + destroySurface = true; + this.destroySurface = false; break; } - if (surfaceTexture != null && !paused && requestRender && surface == null) { + if (surfaceTexture != null && !paused && requestRender + && (surface == null || this.sizeChanged)) { w = width; h = height; - surface = new Surface(surfaceTexture); - initialize = true; + if (surface == null) { + surface = new Surface(surfaceTexture); + createSurface = true; + } + + if (this.sizeChanged) { + sizeChanged = true; + this.sizeChanged = false; + } // Reset the request render flag now, so we can catch new requests // while rendering @@ -81,14 +91,19 @@ public void run() { continue; } - if (initialize) { + if (createSurface) { mapRenderer.onSurfaceCreated(surface); - mapRenderer.onSurfaceChanged( w, h); - - initialize = false; + mapRenderer.onSurfaceChanged(w, h); + createSurface = false; continue; } + if (destroySurface) { + mapRenderer.onSurfaceDestroyed(); + destroySurface = false; + break; + } + // If the surface size has changed inform the map renderer. if (sizeChanged) { mapRenderer.onSurfaceChanged(w, h);