From cdb69d24b8c26915d509d157bf925d996eec3e6d Mon Sep 17 00:00:00 2001
From: Tor Lillqvist <tml@collabora.com>
Date: Wed, 15 Oct 2014 12:08:38 +0300
Subject: If loading a document fails, try restarting the 'main loop' and try
 again

Does not work, though, we end up with a crash that is hard to debug thanks to
the rubbish tool-chain.

Change-Id: Ie1954e35e649fac8dd106f0ccbc6951c4a6c1c63
---
 .../src/java/org/libreoffice/LOKitTileProvider.java       | 15 ++++++++++++++-
 1 file changed, 14 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 bd1b27bddc24..7e90987efa16 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -16,7 +16,7 @@ import java.nio.ByteBuffer;
 public class LOKitTileProvider implements TileProvider {
     private static final String LOGTAG = LOKitTileProvider.class.getSimpleName();
     private static int TILE_SIZE = 256;
-    private final Office mOffice;
+    private Office mOffice;
     private Document mDocument;
     private final LayerController mLayerController;
     private final float mTileWidth;
@@ -42,6 +42,19 @@ public class LOKitTileProvider implements TileProvider {
         mInputFile = input;
         mDocument = mOffice.documentLoad(input);
 
+        if (mDocument == null) {
+            Log.i(LOGTAG, "====> mOffice.documentLoad() returned null, trying to restart 'Office' and loading again");
+            mOffice.destroy();
+            Log.i(LOGTAG, "====> mOffice.destroy() done");
+            long handle = LibreOfficeKit.getLibreOfficeKitHandle();
+            Log.i(LOGTAG, "====> getLibreOfficeKitHandle() = " + handle);
+            mOffice = new Office(handle);
+            Log.i(LOGTAG, "====> new Office created");
+            mDocument = mOffice.documentLoad(input);
+        }
+
+        Log.i(LOGTAG, "====> mDocument = " + mDocument);
+
         if (checkDocument()) {
             int parts = mDocument.getParts();
             Log.i(LOGTAG, "Document parts: " + parts);
-- 
cgit