JAL-2349 JAL-3855 bizarre resizing exception when resizing protein alignment for...
authorJim Procter <j.procter@dundee.ac.uk>
Sun, 30 Oct 2022 23:22:32 +0000 (23:22 +0000)
committerJim Procter <j.procter@dundee.ac.uk>
Sun, 30 Oct 2022 23:22:32 +0000 (23:22 +0000)
src/jalview/gui/AnnotationPanel.java

index c3b44ce..786696c 100755 (executable)
@@ -1284,24 +1284,37 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     if (image == null || imgWidth != image.getWidth(this)
             || image.getHeight(this) != getHeight())
     {
-      try
-      {
-        image = new BufferedImage(imgWidth,
-                ap.getAnnotationPanel().getHeight(),
-                BufferedImage.TYPE_INT_RGB);
-      } catch (OutOfMemoryError oom)
+      boolean tried = false;
+      image = null;
+      while (image == null && !tried)
       {
         try
         {
-          System.gc();
-        } catch (Exception x)
+          image = new BufferedImage(imgWidth,
+                  ap.getAnnotationPanel().getHeight(),
+                  BufferedImage.TYPE_INT_RGB);
+          tried = true;
+        } catch (IllegalArgumentException exc)
         {
+          System.err.println(
+                  "Serious issue with viewport geometry imgWidth requested was "
+                          + imgWidth);
+          return;
+        } catch (OutOfMemoryError oom)
+        {
+          try
+          {
+            System.gc();
+          } catch (Exception x)
+          {
+          }
+          ;
+          new OOMWarning(
+                  "Couldn't allocate memory to redraw screen. Please restart Jalview",
+                  oom);
+          return;
         }
-        ;
-        new OOMWarning(
-                "Couldn't allocate memory to redraw screen. Please restart Jalview",
-                oom);
-        return;
+
       }
       gg = (Graphics2D) image.getGraphics();