Skip to content

Commit 6c88f72

Browse files
Fix TextureMode crash (#3144)
1 parent 5b45d70 commit 6c88f72

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

platform/android/MapLibreAndroid/src/vulkan/java/org/maplibre/android/maps/renderer/textureview/VulkanTextureViewRenderThread.java

+26-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public void run() {
2323

2424
while (true) {
2525
Runnable event = null;
26-
boolean initialize = false;
26+
boolean createSurface = false;
27+
boolean destroySurface = false;
28+
boolean sizeChanged = false;
2729
int w = -1;
2830
int h = -1;
2931

@@ -41,20 +43,28 @@ public void run() {
4143
break;
4244
}
4345

44-
if (destroySurface) {
45-
destroySurface = false;
46-
mapRenderer.onSurfaceDestroyed();
46+
if (this.destroySurface) {
4747
surface = null;
48+
destroySurface = true;
49+
this.destroySurface = false;
4850
break;
4951
}
5052

51-
if (surfaceTexture != null && !paused && requestRender && surface == null) {
53+
if (surfaceTexture != null && !paused && requestRender
54+
&& (surface == null || this.sizeChanged)) {
5255

5356
w = width;
5457
h = height;
55-
surface = new Surface(surfaceTexture);
5658

57-
initialize = true;
59+
if (surface == null) {
60+
surface = new Surface(surfaceTexture);
61+
createSurface = true;
62+
}
63+
64+
if (this.sizeChanged) {
65+
sizeChanged = true;
66+
this.sizeChanged = false;
67+
}
5868

5969
// Reset the request render flag now, so we can catch new requests
6070
// while rendering
@@ -81,14 +91,19 @@ public void run() {
8191
continue;
8292
}
8393

84-
if (initialize) {
94+
if (createSurface) {
8595
mapRenderer.onSurfaceCreated(surface);
86-
mapRenderer.onSurfaceChanged( w, h);
87-
88-
initialize = false;
96+
mapRenderer.onSurfaceChanged(w, h);
97+
createSurface = false;
8998
continue;
9099
}
91100

101+
if (destroySurface) {
102+
mapRenderer.onSurfaceDestroyed();
103+
destroySurface = false;
104+
break;
105+
}
106+
92107
// If the surface size has changed inform the map renderer.
93108
if (sizeChanged) {
94109
mapRenderer.onSurfaceChanged(w, h);

0 commit comments

Comments
 (0)