From 94ec99db8a35094758f240451a8a7acbe4bab540 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 21 Jan 2015 14:55:27 +0100 Subject: android: fix crash in tile provider while closing the document The problem was that for large documents if "back" was pressed quickly, then we closed the document, but rendering thumbnails for the different parts was still in progress. Just make sure we don't crash when the underlying document is gone. E/AndroidRuntime( 8902): java.lang.NullPointerException E/AndroidRuntime( 8902): at org.libreoffice.LOKitTileProvider.thumbnail(LOKitTileProvider.java:244) E/AndroidRuntime( 8902): at org.libreoffice.ThumbnailCreator$ThumbnailCreationTask.getThumbnail(ThumbnailCreator.java:78) E/AndroidRuntime( 8902): at org.libreoffice.LOKitThread.createThumbnail(LOKitThread.java:170) E/AndroidRuntime( 8902): at org.libreoffice.LOKitThread.processEvent(LOKitThread.java:148) E/AndroidRuntime( 8902): at org.libreoffice.LOKitThread.run(LOKitThread.java:120) Change-Id: I93e8e1ea19545ca196ef6f59d19528bb42f3676d --- .../LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'android') diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java index 0970bbbc2a0c..78a592bce704 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java @@ -241,7 +241,8 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback Log.w(LOGTAG, "Thumbnail size: " + getPageWidth() + " " + getPageHeight() + " " + widthPixel + " " + heightPixel); ByteBuffer buffer = ByteBuffer.allocateDirect(widthPixel * heightPixel * 4); - mDocument.paintTile(buffer, widthPixel, heightPixel, 0, 0, (int) mWidthTwip, (int) mHeightTwip); + if (mDocument != null) + mDocument.paintTile(buffer, widthPixel, heightPixel, 0, 0, (int) mWidthTwip, (int) mHeightTwip); Bitmap bitmap = Bitmap.createBitmap(widthPixel, heightPixel, Bitmap.Config.ARGB_8888); bitmap.copyPixelsFromBuffer(buffer); @@ -287,12 +288,18 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback @Override public void changePart(int partIndex) { + if (mDocument == null) + return; + mDocument.setPart(partIndex); resetDocumentSize(); } @Override public int getCurrentPartNumber() { + if (mDocument == null) + return 0; + return mDocument.getPart(); } -- cgit