From 6c88f72b6da3b9dc48c4ca5a0e3e49df8fa8138c Mon Sep 17 00:00:00 2001 From: Adrian Cojocaru Date: Tue, 21 Jan 2025 19:55:57 +0200 Subject: [PATCH] Fix TextureMode crash (#3144) --- .../VulkanTextureViewRenderThread.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) 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 be04ae5c6..3b8a0715b 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 class VulkanTextureViewRenderThread extends TextureViewRenderThread { 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 class VulkanTextureViewRenderThread extends TextureViewRenderThread { 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 class VulkanTextureViewRenderThread extends TextureViewRenderThread { 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);