From 6e670b92ab0119650fa78ec4c968f600c077babc Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Sun, 30 Oct 2022 23:22:32 +0000 Subject: [PATCH] JAL-2349 JAL-3855 bizarre resizing exception when resizing protein alignment for a linked CDS protein alignment --- src/jalview/gui/AnnotationPanel.java | 39 ++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index c3b44ce..786696c 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -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(); -- 1.7.10.2