From 672a1e4f80b22ea4935c9ada9f2ba18d23a4d8b0 Mon Sep 17 00:00:00 2001 From: al-noori Date: Fri, 14 Nov 2025 16:07:54 +0100 Subject: [PATCH] Quick fix for print exception of Snippet 292 The fix results from the expected behaviour of the print in Snippet 292 to redraw the control to the GC by clicking the button. This occured as a subproblem in https://github.com/vi-eclipse/Eclipse-Platform/issues/501 because this worked only once. The problem is that after the first click, the label points to the image, where the group printed itself into it via the GC. Clicking a second time, the image gets disposed. Hence, when the group wants to prints again, the label cannot print its image, as it was disposed. The quick fix for it is to force the label not pointing to the image, if it has one. The question why the label is invoked to print its image, whereby not being in the hierarchy of the control (the group) is likely to be connected to an undocumented flag "OS.PW_RENDERFULLCONTENT" in OS.printWindow() which leads back to https://github.com/eclipse-platform/eclipse.platform.swt/issues/373. --- .../src/org/eclipse/swt/snippets/Snippet292.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet292.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet292.java index 1052dff110a..250f3ea908f 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet292.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet292.java @@ -54,7 +54,10 @@ public static void main(String[] args) { button.setText ("Snapshot"); button.addListener (SWT.Selection, e -> { Image image = label.getImage (); - if (image != null) image.dispose (); + if (image != null) { + image.dispose (); + label.setImage(null); + } Rectangle rect = group.getBounds(); image = new Image (display, rect.width, rect.height); GC gc = new GC (image);