pull/696/head
Mattia Iavarone 6 years ago
parent d54cfbbead
commit e6f599d67e
  1. 3
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java
  2. 12
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraEngine.java

@ -275,7 +275,7 @@ public class Camera1Engine extends CameraEngine implements
throw new RuntimeException("Unknown CameraPreview output class."); throw new RuntimeException("Unknown CameraPreview output class.");
} }
} catch (IOException e) { } catch (IOException e) {
LOG.e("unbindFromSurface", "Could not release surface", e); LOG.e("onStopBind", "Could not release surface", e);
} }
return Tasks.forResult(null); return Tasks.forResult(null);
} }
@ -289,6 +289,7 @@ public class Camera1Engine extends CameraEngine implements
mOrchestrator.remove(JOB_FOCUS_END); mOrchestrator.remove(JOB_FOCUS_END);
if (mCamera != null) { if (mCamera != null) {
try { try {
// In certain states, this release() call can take up to various seconds.
LOG.i("onStopEngine:", "Clean up.", "Releasing camera."); LOG.i("onStopEngine:", "Clean up.", "Releasing camera.");
mCamera.release(); mCamera.release();
LOG.i("onStopEngine:", "Clean up.", "Released camera."); LOG.i("onStopEngine:", "Clean up.", "Released camera.");

@ -250,7 +250,8 @@ public abstract class CameraEngine implements
private static class NoOpExceptionHandler implements Thread.UncaughtExceptionHandler { private static class NoOpExceptionHandler implements Thread.UncaughtExceptionHandler {
@Override @Override
public void uncaughtException(@NonNull Thread thread, @NonNull Throwable throwable) { public void uncaughtException(@NonNull Thread thread, @NonNull Throwable throwable) {
// No-op. LOG.w("EXCEPTION:", "In the NoOpExceptionHandler, probably while destroying.",
"Thread:", thread, "Error:", throwable);
} }
} }
@ -273,10 +274,11 @@ public abstract class CameraEngine implements
if (!(throwable instanceof CameraException)) { if (!(throwable instanceof CameraException)) {
// This is unexpected, either a bug or something the developer should know. // This is unexpected, either a bug or something the developer should know.
// Release and crash the UI thread so we get bug reports. // Release and crash the UI thread so we get bug reports.
LOG.e("EXCEPTION:", "Unexpected exception:", throwable); LOG.e("EXCEPTION:", "Unexpected exception! Scheduling destroy...");
mCrashHandler.post(new Runnable() { mCrashHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
LOG.e("EXCEPTION:", "Unexpected exception! Executing destroy...");
destroy(); destroy();
// Throws an unchecked exception without unnecessary wrapping. // Throws an unchecked exception without unnecessary wrapping.
if (throwable instanceof RuntimeException) { if (throwable instanceof RuntimeException) {
@ -290,7 +292,7 @@ public abstract class CameraEngine implements
} }
final CameraException cameraException = (CameraException) throwable; final CameraException cameraException = (CameraException) throwable;
LOG.e("EXCEPTION:", "Received CameraException:", cameraException, LOG.e("EXCEPTION:", "Received CameraException.",
"Engine state:", getState(), "Current thread:", Thread.currentThread()); "Engine state:", getState(), "Current thread:", Thread.currentThread());
if (fromExceptionHandler) { if (fromExceptionHandler) {
// Got to restart the handler. // Got to restart the handler.
@ -352,9 +354,9 @@ public abstract class CameraEngine implements
} }
}); });
try { try {
boolean success = latch.await(6, TimeUnit.SECONDS); boolean success = latch.await(10, TimeUnit.SECONDS);
if (!success) { if (!success) {
LOG.e("DESTROY: Could not destroy synchronously after 6 seconds.", LOG.e("DESTROY: Could not destroy synchronously after 10 seconds.",
"Current thread:", Thread.currentThread(), "Current thread:", Thread.currentThread(),
"Handler thread: ", mHandler.getThread()); "Handler thread: ", mHandler.getThread());
} }

Loading…
Cancel
Save