JAL-2665 OOM check
[jalview.git] / 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)
     {