Avoid stackoverflows on zoom/ev, fixes #856

pull/953/head
Mattia Iavarone 5 years ago
parent 9c86ffa750
commit 71177d9f2a
  1. 10
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java
  2. 10
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java

@ -623,7 +623,10 @@ public class Camera1Engine extends CameraBaseEngine implements
public void setZoom(final float zoom, @Nullable final PointF[] points, final boolean notify) { public void setZoom(final float zoom, @Nullable final PointF[] points, final boolean notify) {
final float old = mZoomValue; final float old = mZoomValue;
mZoomValue = zoom; mZoomValue = zoom;
mZoomTask = getOrchestrator().scheduleStateful("zoom (" + zoom + ")", // Zoom requests can be high frequency (e.g. linked to touch events), so
// we remove the task before scheduling to avoid stack overflows in orchestrator.
getOrchestrator().remove("zoom");
mZoomTask = getOrchestrator().scheduleStateful("zoom",
CameraState.ENGINE, CameraState.ENGINE,
new Runnable() { new Runnable() {
@Override @Override
@ -655,8 +658,11 @@ public class Camera1Engine extends CameraBaseEngine implements
@Nullable final PointF[] points, final boolean notify) { @Nullable final PointF[] points, final boolean notify) {
final float old = mExposureCorrectionValue; final float old = mExposureCorrectionValue;
mExposureCorrectionValue = EVvalue; mExposureCorrectionValue = EVvalue;
// EV requests can be high frequency (e.g. linked to touch events), so
// we remove the task before scheduling to avoid stack overflows in orchestrator.
getOrchestrator().remove("exposure correction");
mExposureCorrectionTask = getOrchestrator().scheduleStateful( mExposureCorrectionTask = getOrchestrator().scheduleStateful(
"exposure correction (" + EVvalue + ")", "exposure correction",
CameraState.ENGINE, CameraState.ENGINE,
new Runnable() { new Runnable() {
@Override @Override

@ -1246,8 +1246,11 @@ public class Camera2Engine extends CameraBaseEngine implements
public void setZoom(final float zoom, final @Nullable PointF[] points, final boolean notify) { public void setZoom(final float zoom, final @Nullable PointF[] points, final boolean notify) {
final float old = mZoomValue; final float old = mZoomValue;
mZoomValue = zoom; mZoomValue = zoom;
// Zoom requests can be high frequency (e.g. linked to touch events), so
// we remove the task before scheduling to avoid stack overflows in orchestrator.
getOrchestrator().remove("zoom");
mZoomTask = getOrchestrator().scheduleStateful( mZoomTask = getOrchestrator().scheduleStateful(
"zoom (" + zoom + ")", "zoom",
CameraState.ENGINE, CameraState.ENGINE,
new Runnable() { new Runnable() {
@Override @Override
@ -1302,8 +1305,11 @@ public class Camera2Engine extends CameraBaseEngine implements
final boolean notify) { final boolean notify) {
final float old = mExposureCorrectionValue; final float old = mExposureCorrectionValue;
mExposureCorrectionValue = EVvalue; mExposureCorrectionValue = EVvalue;
// EV requests can be high frequency (e.g. linked to touch events), so
// we remove the task before scheduling to avoid stack overflows in orchestrator.
getOrchestrator().remove("exposure correction");
mExposureCorrectionTask = getOrchestrator().scheduleStateful( mExposureCorrectionTask = getOrchestrator().scheduleStateful(
"exposure correction (" + EVvalue + ")", "exposure correction",
CameraState.ENGINE, CameraState.ENGINE,
new Runnable() { new Runnable() {
@Override @Override

Loading…
Cancel
Save