JAL-1173 - trap redraw buffer OOM errors. needs a test case - since the dialog doesn...
authorjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 25 Sep 2012 10:20:17 +0000 (11:20 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 25 Sep 2012 10:20:17 +0000 (11:20 +0100)
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)