summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java10
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java6
2 files changed, 15 insertions, 1 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java
index 0e30e459ff93..670e39724aad 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java
@@ -87,4 +87,14 @@ public final class DirectBufferAllocator {
// can't free buffer - leave this to the VM
return null;
}
+
+ public static ByteBuffer guardedAllocate(int size) {
+ ByteBuffer buffer = null;
+ try {
+ buffer = allocate(size);
+ } catch (OutOfMemoryError oomException) {
+ return null;
+ }
+ return buffer;
+ }
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index 0e2db4b91282..752e0a91ea45 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -4,6 +4,7 @@ import android.graphics.Bitmap;
import android.graphics.RectF;
import android.util.Log;
+import org.libreoffice.kit.DirectBufferAllocator;
import org.libreoffice.kit.Document;
import org.libreoffice.kit.LibreOfficeKit;
import org.libreoffice.kit.Office;
@@ -189,7 +190,10 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
@Override
public CairoImage createTile(float x, float y, IntSize tileSize, float zoom) {
- ByteBuffer buffer = ByteBuffer.allocateDirect(tileSize.width * tileSize.height * 4);
+ ByteBuffer buffer = DirectBufferAllocator.guardedAllocate(tileSize.width * tileSize.height * 4);
+ if (buffer == null)
+ return null;
+
CairoImage image = new BufferedCairoImage(buffer, tileSize.width, tileSize.height, CairoImage.FORMAT_ARGB32);
rerenderTile(image, x, y, tileSize, zoom);
return image;