From f76104c61bf4c3c5a092d08a1138ce79278aab76 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 24 Apr 2012 16:16:49 +0100 Subject: Fix crash in android app due to flood of page seeks. Sebras found a way of crashing the MuPDF Android app by seeking quickly back and forth with the page seek bar. After about 30 seconds of frantically tapping either end of it, we'd force close. Examination shows this is due to the Async task queue getting full and throwing an exception. A simple fix is to catch the exception and perform the same tasks in the foreground. Testing indicates that this causes the UI to stall, but it's far preferable to a crash. --- android/src/com/artifex/mupdf/MuPDFPageAdapter.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'android/src') diff --git a/android/src/com/artifex/mupdf/MuPDFPageAdapter.java b/android/src/com/artifex/mupdf/MuPDFPageAdapter.java index 91b30dce..4587e244 100644 --- a/android/src/com/artifex/mupdf/MuPDFPageAdapter.java +++ b/android/src/com/artifex/mupdf/MuPDFPageAdapter.java @@ -65,7 +65,21 @@ public class MuPDFPageAdapter extends BaseAdapter { pageView.setPage(position, result); } }; - sizingTask.execute((Void)null); + try + { + sizingTask.execute((Void)null); + } + catch (java.util.concurrent.RejectedExecutionException e) + { + // If we can't do it in the background, just + // do it in the foreground. + PointF result = mCore.getPageSize(position); + mPageSizes.put(position, result); + // Check that this view hasn't been reused for + // another page since we started + if (pageView.getPage() == position) + pageView.setPage(position, result); + } } return pageView; } -- cgit v1.2.3