summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/jni/mupdf.c12
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFActivity.java5
2 files changed, 15 insertions, 2 deletions
diff --git a/android/jni/mupdf.c b/android/jni/mupdf.c
index 74d9970d..c929e13e 100644
--- a/android/jni/mupdf.c
+++ b/android/jni/mupdf.c
@@ -447,8 +447,18 @@ JNIEXPORT int JNICALL
JNI_FN(MuPDFCore_countPagesInternal)(JNIEnv *env, jobject thiz)
{
globals *glo = get_globals(env, thiz);
+ fz_context *ctx = glo->ctx;
+ int count = 0;
- return fz_count_pages(glo->doc);
+ fz_try(ctx)
+ {
+ count = fz_count_pages(glo->doc);
+ }
+ fz_catch(ctx)
+ {
+ LOGE("exception while counting pages: %s", ctx->error->message);
+ }
+ return count;
}
JNIEXPORT void JNICALL
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
index 4f10e991..be8dca89 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
@@ -312,6 +312,8 @@ public class MuPDFActivity extends Activity
core = openFile(Uri.decode(uri.getEncodedPath()));
}
SearchTaskResult.set(null);
+ if (core.countPages() == 0)
+ core = null;
}
if (core != null && core.needsPassword()) {
requestPassword(savedInstanceState);
@@ -743,7 +745,8 @@ public class MuPDFActivity extends Activity
protected void onPause() {
super.onPause();
- mSearchTask.stop();
+ if (mSearchTask != null)
+ mSearchTask.stop();
if (mFileName != null && mDocView != null) {
SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);