Skip to content

Commit 5deef61

Browse files
GC with Image in unsupported use cases
Logging a warning for GC initialized with unsupported use cases. 1. all dynamic images (retrieved via any of the existing providers). 2. all images for which handles in other zoom values have already been created.
1 parent a3cc110 commit 5deef61

File tree

1 file changed

+16
-0
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+16
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java

+16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.eclipse.swt.internal.gdip.*;
2727
import org.eclipse.swt.internal.image.*;
2828
import org.eclipse.swt.internal.win32.*;
29+
import org.eclipse.swt.widgets.Display;
2930

3031
/**
3132
* Instances of this class are graphics which have been prepared
@@ -1690,6 +1691,18 @@ private ImageHandle init(ImageData i, int zoom) {
16901691
}
16911692
}
16921693

1694+
private void assertCondition(boolean condition, String message) {
1695+
if (condition) {
1696+
RuntimeException ex = new RuntimeException("Assertion failed: " + message);
1697+
Display display = Display.getCurrent();
1698+
if (display != null && display.getRuntimeExceptionHandler() != null) {
1699+
display.getRuntimeExceptionHandler().accept(ex);
1700+
} else {
1701+
throw ex;
1702+
}
1703+
}
1704+
}
1705+
16931706
/**
16941707
* Invokes platform specific functionality to allocate a new GC handle.
16951708
* <p>
@@ -1716,6 +1729,9 @@ public long internal_new_GC (GCData data) {
17161729
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
17171730
}
17181731

1732+
assertCondition(imageProvider != null && (imageProvider instanceof ImageDataProviderWrapper || imageProvider instanceof ImageFileNameProviderWrapper), "Image initialized with ImageDataProvider or ImageFileNameProvider is not supposed to be modified");
1733+
assertCondition(!zoomLevelToImageHandle.isEmpty() && (zoomLevelToImageHandle.size() != 1 || !zoomLevelToImageHandle.containsKey(getZoom())), "Images with handles created for a different zoom level should not be modified");
1734+
17191735
/* Create a compatible HDC for the device */
17201736
long hDC = device.internal_new_GC(null);
17211737
long imageDC = OS.CreateCompatibleDC(hDC);

0 commit comments

Comments
 (0)