From a76bbd0f0b2f966a04a560cb02ba2d926f0e4adb Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 24 Oct 2016 14:14:37 +0100 Subject: Bug 697226: Fix SEGV in Android viewer. As we skip through pages very quickly, it is apparently possible to trigger a SEGV. Alex Talis has given a clear description of the problem on the bug, and proposed this solution. Essentially this tweaks our CancellableAsyncTask class to ensure that we do not destroy the cookie before it has finished being accessed. --- .../src/com/artifex/mupdfdemo/CancellableAsyncTask.java | 10 +++++++--- .../android/viewer/src/com/artifex/mupdfdemo/PageView.java | 14 +++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'platform/android') diff --git a/platform/android/viewer/src/com/artifex/mupdfdemo/CancellableAsyncTask.java b/platform/android/viewer/src/com/artifex/mupdfdemo/CancellableAsyncTask.java index fcb1b744..53d16f57 100644 --- a/platform/android/viewer/src/com/artifex/mupdfdemo/CancellableAsyncTask.java +++ b/platform/android/viewer/src/com/artifex/mupdfdemo/CancellableAsyncTask.java @@ -46,10 +46,16 @@ public class CancellableAsyncTask CancellableAsyncTask.this.onPostExecute(result); task.doCleanup(); } + + @Override + protected void onCancelled(Result result) + { + task.doCleanup(); + } }; } - public void cancelAndWait() + public void cancel() { this.asyncTask.cancel(true); ourTask.doCancel(); @@ -67,8 +73,6 @@ public class CancellableAsyncTask catch (CancellationException e) { } - - ourTask.doCleanup(); } public void execute(Params ... params) diff --git a/platform/android/viewer/src/com/artifex/mupdfdemo/PageView.java b/platform/android/viewer/src/com/artifex/mupdfdemo/PageView.java index 502e0c2b..5f5cc638 100644 --- a/platform/android/viewer/src/com/artifex/mupdfdemo/PageView.java +++ b/platform/android/viewer/src/com/artifex/mupdfdemo/PageView.java @@ -144,12 +144,12 @@ public abstract class PageView extends ViewGroup { private void reinit() { // Cancel pending render task if (mDrawEntire != null) { - mDrawEntire.cancelAndWait(); + mDrawEntire.cancel(); mDrawEntire = null; } if (mDrawPatch != null) { - mDrawPatch.cancelAndWait(); + mDrawPatch.cancel(); mDrawPatch = null; } @@ -229,7 +229,7 @@ public abstract class PageView extends ViewGroup { public void setPage(int page, PointF size) { // Cancel pending render task if (mDrawEntire != null) { - mDrawEntire.cancelAndWait(); + mDrawEntire.cancel(); mDrawEntire = null; } @@ -603,7 +603,7 @@ public abstract class PageView extends ViewGroup { // Stop the drawing of previous patch if still going if (mDrawPatch != null) { - mDrawPatch.cancelAndWait(); + mDrawPatch.cancel(); mDrawPatch = null; } @@ -647,12 +647,12 @@ public abstract class PageView extends ViewGroup { public void update() { // Cancel pending render task if (mDrawEntire != null) { - mDrawEntire.cancelAndWait(); + mDrawEntire.cancel(); mDrawEntire = null; } if (mDrawPatch != null) { - mDrawPatch.cancelAndWait(); + mDrawPatch.cancel(); mDrawPatch = null; } @@ -673,7 +673,7 @@ public abstract class PageView extends ViewGroup { public void removeHq() { // Stop the drawing of the patch if still going if (mDrawPatch != null) { - mDrawPatch.cancelAndWait(); + mDrawPatch.cancel(); mDrawPatch = null; } -- cgit v1.2.3