Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6002,8 +6002,11 @@ Point textExtentInPixels(String string, int flags) {
return new Point(rect.right, rect.bottom);
}

void refreshFor(Drawable drawable, ImageHandle imageHandle) {
void reapplyTo(Drawable drawable, ImageHandle imageHandle) {
if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (!data.reapplicable) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
destroy();
GCData newData = new GCData();
originalData.copyTo(newData);
Expand Down Expand Up @@ -6109,9 +6112,13 @@ int getZoom() {
}

private void storeAndApplyOperationForExistingHandle(Operation operation) {
removePreviousOperationIfSupercededBy(operation);
operations.add(operation);
operation.apply();
if (data.reapplicable) {
removePreviousOperationIfSupercededBy(operation);
operations.add(operation);
} else {
operation.disposeAll();
}
}

private void removePreviousOperationIfSupercededBy(Operation operation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public final class GCData {
public int alpha = 0xFF;
public int nativeZoom;
int imageZoom;
boolean reapplicable;

public Image image;
public PAINTSTRUCT ps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2333,6 +2333,7 @@ public Collection<Integer> getPreservedZoomLevels() {

@Override
protected long configureGCData(GCData data) {
data.reapplicable = true;
return configureGC(data, new ZoomContext(DPIUtil.getDeviceZoom(), DPIUtil.getNativeDeviceZoom()));
}

Expand Down Expand Up @@ -2374,7 +2375,7 @@ protected DestroyableImageHandle newImageHandle(ZoomContext zoomContext) {
GC currentGC = memGC;
memGC = null;
DestroyableImageHandle imageHandle = createHandle(targetZoom);
currentGC.refreshFor(new DrawableWrapper(Image.this, zoomContext), imageHandle);
currentGC.reapplyTo(new DrawableWrapper(Image.this, zoomContext), imageHandle);
return imageHandle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ public void test_drawImageLorg_eclipse_swt_graphics_ImageIIII_ImageDataAtSizePro
Exception e = assertThrows(IllegalArgumentException.class, () -> gc.drawImage(image, 0, 0, 1, 1));
assertSWTProblem("Incorrect exception thrown for provider == null", SWT.ERROR_INVALID_ARGUMENT, e);
} finally {
image.dispose();
drawToImage.dispose();
image.dispose();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change necessary? Does this mean that production code also needs to pay attention to the order in which the images have been created when disposing them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a test for an exception thrown during a drawImage call when a null provider is used. The resulting state of the GC after such a failure is undefined and potentially having it unnecessarily try to copy the image that was attempted to be drawn because of the disposal order is just a risk of the test failing because of an unrelated exception. In practice it does not make any difference as the code fails because of the failing draw operation anyway and probably no one wraps a drawImage call into a try-finally to clean up the involved resources where this order could make any difference at all.

}
}

Expand Down
Loading