JAL-1173 - trap redraw buffer OOM errors. needs a test case - since the dialog doesn...
[jalview.git] / src / jalview / gui / AnnotationPanel.java
index 411c244..23d8341 100755 (executable)
@@ -754,8 +754,17 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     if (image == null || imgWidth != image.getWidth()
             || image.getHeight(this) != getHeight())
     {
+      try {
       image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
               BufferedImage.TYPE_INT_RGB);
+      } catch (OutOfMemoryError oom)
+      {
+        try {
+          System.gc();
+        } catch (Exception x){};
+        new OOMWarning("Couldn't allocate memory to redraw screen. Please restart Jalview", oom);
+        return;
+      }
       gg = (Graphics2D) image.getGraphics();
 
       if (av.antiAlias)