@@ -80,8 +80,6 @@ public class CameraRenderer extends Thread implements TextureView.SurfaceTexture
80
80
private CameraFilter selectedFilter ;
81
81
private SparseArray <CameraFilter > cameraFilterMap = new SparseArray <>();
82
82
83
- private boolean exit = false ;
84
-
85
83
public CameraRenderer (Context context ) {
86
84
this .context = context ;
87
85
}
@@ -101,14 +99,18 @@ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
101
99
camera .stopPreview ();
102
100
camera .release ();
103
101
}
104
- exit = true ;
102
+ interrupt () ;
105
103
CameraFilter .release ();
106
104
107
105
return true ;
108
106
}
109
107
110
108
@ Override
111
109
public void onSurfaceTextureAvailable (SurfaceTexture surface , int width , int height ) {
110
+ if (isAlive ()) {
111
+ interrupt ();
112
+ }
113
+
112
114
surfaceTexture = surface ;
113
115
GLES20 .glViewport (0 , 0 , gwidth = width , gheight = height );
114
116
@@ -167,25 +169,26 @@ public void run() {
167
169
}
168
170
169
171
// Render loop
170
- while (!exit ) {
171
- GLES20 .glClear (GLES20 .GL_COLOR_BUFFER_BIT );
172
+ while (!Thread .currentThread ().isInterrupted ()) {
173
+ try {
174
+ GLES20 .glClear (GLES20 .GL_COLOR_BUFFER_BIT );
172
175
173
- // Update the camera preview texture
174
- synchronized (this ) {
175
- cameraSurfaceTexture .updateTexImage ();
176
- }
176
+ // Update the camera preview texture
177
+ synchronized (this ) {
178
+ cameraSurfaceTexture .updateTexImage ();
179
+ }
177
180
178
- // Draw camera preview
179
- selectedFilter .draw (cameraTextureId , gwidth , gheight );
181
+ // Draw camera preview
182
+ selectedFilter .draw (cameraTextureId , gwidth , gheight );
180
183
181
- // Flush
182
- GLES20 .glFlush ();
183
- egl10 .eglSwapBuffers (eglDisplay , eglSurface );
184
+ // Flush
185
+ GLES20 .glFlush ();
186
+ egl10 .eglSwapBuffers (eglDisplay , eglSurface );
184
187
185
- try {
186
188
Thread .sleep (DRAW_INTERVAL );
189
+
187
190
} catch (InterruptedException e ) {
188
- // Ignore
191
+ Thread . currentThread (). interrupt ();
189
192
}
190
193
}
191
194
0 commit comments