commit 49595e4b976c8e3dbbccd6830d5b68bcf3b789e3
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Aug 26 15:53:21 2020 +0100

    Fix for one bug seen in Firebase and additional debugging for another.

diff --git a/src/main/java/org/distorted/main/RubikSurfaceView.java b/src/main/java/org/distorted/main/RubikSurfaceView.java
index d6f8f4fe..449b942b 100644
--- a/src/main/java/org/distorted/main/RubikSurfaceView.java
+++ b/src/main/java/org/distorted/main/RubikSurfaceView.java
@@ -389,7 +389,7 @@ public class RubikSurfaceView extends GLSurfaceView
         mInitDistance = distNow;
 
         RubikObject object = mPreRender.getObject();
-        object.setObjectRatio(distQuot);
+        if( object!=null ) object.setObjectRatio(distQuot);
         }
       else
         {
diff --git a/src/main/java/org/distorted/objects/RubikCube.java b/src/main/java/org/distorted/objects/RubikCube.java
index 8d2e0976..6130c0b4 100644
--- a/src/main/java/org/distorted/objects/RubikCube.java
+++ b/src/main/java/org/distorted/objects/RubikCube.java
@@ -23,6 +23,8 @@ import android.content.res.Resources;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 
+import com.google.firebase.crashlytics.FirebaseCrashlytics;
+
 import org.distorted.library.effect.VertexEffectDeform;
 import org.distorted.library.effect.VertexEffectMove;
 import org.distorted.library.effect.VertexEffectRotate;
@@ -508,8 +510,8 @@ class RubikCube extends RubikObject
     StringBuilder objectString = new StringBuilder();
     int size = getSize();
     int len = size*size;
-    int cubitIndex, row, col;
-    int color;
+    int cubitIndex=-1, row=-1, col=-1;
+    int color=-1, face=-1;
 
     final int RIGHT= 0;
     final int LEFT = 1;
@@ -520,23 +522,36 @@ class RubikCube extends RubikObject
 
     final char[] FACE_NAMES = { 'R', 'L', 'U', 'D', 'F', 'B'};
 
+/////////////////////
+// LIVE DEBUGGING
+/////////////////////
+try
+  {
+/////////////////////
+
+    face = UP;
+
     for(int i=0; i<len; i++)
       {
       row = i/size;
       col = i%size;
 
       cubitIndex = col<size-1 ? (size-1)*(size+4*col) + row : 6*size*size - 13*size + 8 + row;
-      color = getCubitFaceColorIndex(cubitIndex,UP);
+      color = getCubitFaceColorIndex(cubitIndex,face);
       objectString.append(FACE_NAMES[color]);
       }
 
+    face = RIGHT;
+
     for(int i=0; i<len; i++)
       {
       cubitIndex = 6*size*size - 12*size +7 - i;
-      color = getCubitFaceColorIndex(cubitIndex,RIGHT);
+      color = getCubitFaceColorIndex(cubitIndex,face);
       objectString.append(FACE_NAMES[color]);
       }
 
+     face = FRONT;
+
     for(int i=0; i<len; i++)
       {
       row = i/size;
@@ -550,30 +565,36 @@ class RubikCube extends RubikObject
         else         cubitIndex = size*size + size-1 + 4*(col-1)*(size-1) + 2*(size-1-row);
         }
 
-      color = getCubitFaceColorIndex(cubitIndex,FRONT);
+      color = getCubitFaceColorIndex(cubitIndex,face);
       objectString.append(FACE_NAMES[color]);
       }
 
+    face = DOWN;
+
     for(int i=0; i<len; i++)
       {
       row = i/size;
       col = i%size;
 
       cubitIndex = col==0 ? size-1-row : size*size + size-1 + 4*(col-1)*(size-1) - row;
-      color = getCubitFaceColorIndex(cubitIndex,DOWN);
+      color = getCubitFaceColorIndex(cubitIndex,face);
       objectString.append(FACE_NAMES[color]);
       }
 
+    face = LEFT;
+
     for(int i=0; i<len; i++)
       {
       row = i/size;
       col = i%size;
 
       cubitIndex = (size-1-row)*size + col;
-      color = getCubitFaceColorIndex(cubitIndex,LEFT);
+      color = getCubitFaceColorIndex(cubitIndex,face);
       objectString.append(FACE_NAMES[color]);
       }
 
+    face = BACK;
+
     for(int i=0; i<len; i++)
       {
       row = i/size;
@@ -587,10 +608,30 @@ class RubikCube extends RubikObject
         else              cubitIndex = size*size + 4*(size-2-col)*(size-1) + size + 2*(size-2-row);
         }
 
-      color = getCubitFaceColorIndex(cubitIndex,BACK);
+      color = getCubitFaceColorIndex(cubitIndex,face);
       objectString.append(FACE_NAMES[color]);
       }
 
+/////////////////////
+  }
+catch(java.lang.ArrayIndexOutOfBoundsException ex)
+  {
+  FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
+
+  String str="";
+  for(int i=0; i<NUM_CUBITS; i++)
+    {
+    str += (CUBITS[i].mQuatIndex+" ");
+    }
+
+  crashlytics.setCustomKey("ObjectString", "color="+color+" cubitIndex="+cubitIndex+" face="+face+" row="+row+" col="+col );
+  crashlytics.setCustomKey("Quaternion", "NUM_CUBITS: "+NUM_CUBITS+" quats: "+str );
+  crashlytics.recordException(ex);
+  }
+/////////////////////
+// END LIVE DEBUGGING
+/////////////////////
+
     return objectString.toString();
     }
 }
