JAL-2665 OOM check
authorkiramt <k.mourao@dundee.ac.uk>
Tue, 29 Aug 2017 09:48:54 +0000 (10:48 +0100)
committerkiramt <k.mourao@dundee.ac.uk>
Tue, 29 Aug 2017 09:48:54 +0000 (10:48 +0100)
src/jalview/gui/SeqCanvas.java

index 8004cac..f34ab2c 100755 (executable)
@@ -453,8 +453,20 @@ public class SeqCanvas extends JComponent implements ViewportListenerI
           int canvasHeight, int startRes)
   {
     SequenceGroup group = av.getSelectionGroup();
-    BufferedImage selectImage = new BufferedImage(canvasWidth, canvasHeight,
-            BufferedImage.TYPE_INT_ARGB); // ARGB so alpha compositing works
+    BufferedImage selectImage = null;
+
+    try
+    {
+      selectImage = new BufferedImage(canvasWidth, canvasHeight,
+              BufferedImage.TYPE_INT_ARGB); // ARGB so alpha compositing works
+    } catch (OutOfMemoryError er)
+    {
+      System.gc();
+      System.err.println("Print image OutOfMemory Error.\n" + er);
+      new OOMWarning("Creating wrapped alignment image for printing", er);
+
+      return;
+    }
 
     if (group != null)
     {