Kaydet (Commit) a5e2c361 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Miklos Vajna

android: guard buffer allocation and return null if alloc. fails

Change-Id: I684c7af245cc755b94f69e175c652d161e0f643a
üst 1e4f6eeb
......@@ -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;
}
}
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment