Add extra debugging for outofbounds exception
[nikiroo-utils.git] / src / jexer / backend / ECMA48Terminal.java
index dfc3edbe8a528633db9e2dfdd62e2a75ac29cba2..252e80c4123a85d94af54a15e734ac8ade3c12ea 100644 (file)
@@ -2851,14 +2851,32 @@ public class ECMA48Terminal extends LogicalScreen
 
         int [] rgbArray;
         for (int i = 0; i < cells.size() - 1; i++) {
-            if (cells.get(i).isInvertedImage()) {
+            int tileWidth = Math.min(cells.get(i).getImage().getWidth(),
+                imageWidth);
+            int tileHeight = Math.min(cells.get(i).getImage().getHeight(),
+                imageHeight);
+            if (false && cells.get(i).isInvertedImage()) {
+                // I used to put an all-white cell over the cursor, don't do
+                // that anymore.
                 rgbArray = new int[imageWidth * imageHeight];
                 for (int j = 0; j < rgbArray.length; j++) {
                     rgbArray[j] = 0xFFFFFF;
                 }
             } else {
-                rgbArray = cells.get(i).getImage().getRGB(0, 0,
-                    imageWidth, imageHeight, null, 0, imageWidth);
+                try {
+                    rgbArray = cells.get(i).getImage().getRGB(0, 0,
+                        tileWidth, tileHeight, null, 0, tileWidth);
+                } catch (Exception e) {
+                    throw new RuntimeException("image " + imageWidth + "x" +
+                        imageHeight +
+                        "tile " + tileWidth + "x" +
+                        tileHeight +
+                        " cells.get(i).getImage() " +
+                        cells.get(i).getImage() +
+                        " i " + i +
+                        " fullWidth " + fullWidth +
+                        " fullHeight " + fullHeight, e);
+                }
             }
 
             /*
@@ -2869,9 +2887,9 @@ public class ECMA48Terminal extends LogicalScreen
                 fullWidth, fullHeight, cells.size(), getTextWidth());
              */
 
-            image.setRGB(i * imageWidth, 0, imageWidth, imageHeight,
-                rgbArray, 0, imageWidth);
-            if (imageHeight < fullHeight) {
+            image.setRGB(i * imageWidth, 0, tileWidth, tileHeight,
+                rgbArray, 0, tileWidth);
+            if (tileHeight < fullHeight) {
                 int backgroundColor = cells.get(i).getBackground().getRGB();
                 for (int imageX = 0; imageX < image.getWidth(); imageX++) {
                     for (int imageY = imageHeight; imageY < fullHeight;
@@ -2883,14 +2901,22 @@ public class ECMA48Terminal extends LogicalScreen
             }
         }
         totalWidth -= ((cells.size() - 1) * imageWidth);
-        if (cells.get(cells.size() - 1).isInvertedImage()) {
+        if (false && cells.get(cells.size() - 1).isInvertedImage()) {
+            // I used to put an all-white cell over the cursor, don't do that
+            // anymore.
             rgbArray = new int[totalWidth * imageHeight];
             for (int j = 0; j < rgbArray.length; j++) {
                 rgbArray[j] = 0xFFFFFF;
             }
         } else {
-            rgbArray = cells.get(cells.size() - 1).getImage().getRGB(0, 0,
-                totalWidth, imageHeight, null, 0, totalWidth);
+            try {
+                rgbArray = cells.get(cells.size() - 1).getImage().getRGB(0, 0,
+                    totalWidth, imageHeight, null, 0, totalWidth);
+            } catch (Exception e) {
+                throw new RuntimeException("image " + imageWidth + "x" +
+                    imageHeight + " cells.get(cells.size() - 1).getImage() " +
+                    cells.get(cells.size() - 1).getImage(), e);
+            }
         }
         image.setRGB((cells.size() - 1) * imageWidth, 0, totalWidth,
             imageHeight, rgbArray, 0, totalWidth);
@@ -2994,6 +3020,7 @@ public class ECMA48Terminal extends LogicalScreen
                     assert (data >= 0);
                     assert (data < 64);
                     data += 63;
+
                     if (data == oldData) {
                         oldDataCount++;
                     } else {
@@ -3006,6 +3033,7 @@ public class ECMA48Terminal extends LogicalScreen
                         oldDataCount = 1;
                         oldData = data;
                     }
+
                 } // for (int imageX = 0; imageX < image.getWidth(); imageX++)
 
                 // Emit the last sequence.