From f36669bf2be5a1ce10a98f9f741f3678cd2553ae Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Wed, 20 Aug 2025 11:33:36 +0200 Subject: [PATCH] [Win32] Avoid broken UI when DPI change handler fails #2432 In case a DPI change handler fails with an exception, the complete rescaling process may fail. As an example, it may happen that an image set to an Item has already been disposed when a DPI change event occurs, but the DPI change handler still tries to set that image on the item again, leading to an exception because of the image being disposed. This change ensures that an exception happening when processing a DPI change handler does not result in a complete rescaling failure and instead reports the listener error to the Display. Contributes to https://github.com/eclipse-platform/eclipse.platform.swt/issues/2432 --- .../org/eclipse/swt/internal/DPIZoomChangeRegistry.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DPIZoomChangeRegistry.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DPIZoomChangeRegistry.java index 3ba6d4adc37..2547860fe91 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DPIZoomChangeRegistry.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/DPIZoomChangeRegistry.java @@ -53,7 +53,11 @@ public static void applyChange(Widget widget, int newZoom, float scalingFactor) Class clazz = entry.getKey(); DPIZoomChangeHandler handler = entry.getValue(); if (clazz.isInstance(widget)) { - handler.handleDPIChange(widget, newZoom, scalingFactor); + try { + handler.handleDPIChange(widget, newZoom, scalingFactor); + } catch (RuntimeException ex) { + widget.getDisplay().getRuntimeExceptionHandler().accept(ex); + } } } Event event = new Event();