Skip to content

Commit 5bfc6ee

Browse files
committed
Make disposal of BufferedGraphicsSource more robust #875
The call to GC.drawImage() may throw an IllegalArgumentException when dealing with fractional scaling. In such a case, not all SWT resources are destroyed, leading to memory leaks. Any exception thrown by this operation is caught and logged, in order to allow the disposal to finish gracefully. Closes #875
1 parent e319539 commit 5bfc6ee

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

org.eclipse.draw2d/src/org/eclipse/draw2d/BufferedGraphicsSource.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
import org.eclipse.swt.widgets.Control;
2222

2323
import org.eclipse.draw2d.geometry.Rectangle;
24+
import org.eclipse.draw2d.internal.Logger;
2425

2526
class BufferedGraphicsSource implements GraphicsSource {
26-
27+
private static final Logger LOGGER = Logger.getLogger(BufferedGraphicsSource.class);
2728
private Image imageBuffer;
2829
private GC imageGC;
2930
private GC controlGC;
@@ -66,8 +67,14 @@ public void flushGraphics(Rectangle region) {
6667
*/
6768
if (imageBuffer != null) {
6869
imageGC.dispose();
69-
controlGC.drawImage(getImage(), 0, 0, inUse.width, inUse.height, inUse.x, inUse.y, inUse.width,
70-
inUse.height);
70+
try {
71+
// Make sure the SWT resources are properly disposed in case of an error
72+
// See https://github.com/eclipse-gef/gef-classic/issues/875
73+
controlGC.drawImage(getImage(), 0, 0, inUse.width, inUse.height, inUse.x, inUse.y, inUse.width,
74+
inUse.height);
75+
} catch (IllegalArgumentException e) {
76+
LOGGER.error(e.getMessage(), e);
77+
}
7178
imageBuffer.dispose();
7279
imageBuffer = null;
7380
imageGC = null;

0 commit comments

Comments
 (0)