@@ -23,7 +23,9 @@ public void run() {
23
23
24
24
while (true ) {
25
25
Runnable event = null ;
26
- boolean initialize = false ;
26
+ boolean createSurface = false ;
27
+ boolean destroySurface = false ;
28
+ boolean sizeChanged = false ;
27
29
int w = -1 ;
28
30
int h = -1 ;
29
31
@@ -41,20 +43,28 @@ public void run() {
41
43
break ;
42
44
}
43
45
44
- if (destroySurface ) {
45
- destroySurface = false ;
46
- mapRenderer .onSurfaceDestroyed ();
46
+ if (this .destroySurface ) {
47
47
surface = null ;
48
+ destroySurface = true ;
49
+ this .destroySurface = false ;
48
50
break ;
49
51
}
50
52
51
- if (surfaceTexture != null && !paused && requestRender && surface == null ) {
53
+ if (surfaceTexture != null && !paused && requestRender
54
+ && (surface == null || this .sizeChanged )) {
52
55
53
56
w = width ;
54
57
h = height ;
55
- surface = new Surface (surfaceTexture );
56
58
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
+ }
58
68
59
69
// Reset the request render flag now, so we can catch new requests
60
70
// while rendering
@@ -81,14 +91,19 @@ public void run() {
81
91
continue ;
82
92
}
83
93
84
- if (initialize ) {
94
+ if (createSurface ) {
85
95
mapRenderer .onSurfaceCreated (surface );
86
- mapRenderer .onSurfaceChanged ( w , h );
87
-
88
- initialize = false ;
96
+ mapRenderer .onSurfaceChanged (w , h );
97
+ createSurface = false ;
89
98
continue ;
90
99
}
91
100
101
+ if (destroySurface ) {
102
+ mapRenderer .onSurfaceDestroyed ();
103
+ destroySurface = false ;
104
+ break ;
105
+ }
106
+
92
107
// If the surface size has changed inform the map renderer.
93
108
if (sizeChanged ) {
94
109
mapRenderer .onSurfaceChanged (w , h );
0 commit comments