Skip to content

Commit ec2b7c4

Browse files
author
nekocode
committed
Update gradle & Try to fix Issue#8
1 parent 74d87f6 commit ec2b7c4

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

app/src/main/java/cn/nekocode/camerafilter/CameraRenderer.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ public class CameraRenderer extends Thread implements TextureView.SurfaceTexture
8080
private CameraFilter selectedFilter;
8181
private SparseArray<CameraFilter> cameraFilterMap = new SparseArray<>();
8282

83-
private boolean exit = false;
84-
8583
public CameraRenderer(Context context) {
8684
this.context = context;
8785
}
@@ -101,14 +99,18 @@ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
10199
camera.stopPreview();
102100
camera.release();
103101
}
104-
exit = true;
102+
interrupt();
105103
CameraFilter.release();
106104

107105
return true;
108106
}
109107

110108
@Override
111109
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
110+
if (isAlive()) {
111+
interrupt();
112+
}
113+
112114
surfaceTexture = surface;
113115
GLES20.glViewport(0, 0, gwidth = width, gheight = height);
114116

@@ -167,25 +169,26 @@ public void run() {
167169
}
168170

169171
// 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);
172175

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+
}
177180

178-
// Draw camera preview
179-
selectedFilter.draw(cameraTextureId, gwidth, gheight);
181+
// Draw camera preview
182+
selectedFilter.draw(cameraTextureId, gwidth, gheight);
180183

181-
// Flush
182-
GLES20.glFlush();
183-
egl10.eglSwapBuffers(eglDisplay, eglSurface);
184+
// Flush
185+
GLES20.glFlush();
186+
egl10.eglSwapBuffers(eglDisplay, eglSurface);
184187

185-
try {
186188
Thread.sleep(DRAW_INTERVAL);
189+
187190
} catch (InterruptedException e) {
188-
// Ignore
191+
Thread.currentThread().interrupt();
189192
}
190193
}
191194

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.1.2'
8+
classpath 'com.android.tools.build:gradle:2.1.3'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Dec 28 10:00:20 PST 2015
1+
#Mon Aug 22 15:08:34 CST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

0 commit comments

Comments
 (0)