[Win32] Fix drawImage() failing for an empty image - #3463
Merged
Conversation
HeikoKlare
force-pushed
the
fix-issue-3442
branch
from
July 24, 2026 14:33
4a01bf7 to
dfd4a4b
Compare
Contributor
HeikoKlare
marked this pull request as ready for review
July 24, 2026 15:00
r-mennig
approved these changes
Jul 27, 2026
| return 100; | ||
| } | ||
| TreeSet<Integer> availableZooms = new TreeSet<>(imageHandleManager.getAllZooms()); | ||
| return availableZooms.contains(zoom) ? zoom : Optional.ofNullable(availableZooms.higher(zoom)).orElse(availableZooms.lower(zoom)); |
There was a problem hiding this comment.
Using Optionals here just for chaining makes the code harder to read (in my opinion):
Suggested change
| return availableZooms.contains(zoom) ? zoom : Optional.ofNullable(availableZooms.higher(zoom)).orElse(availableZooms.lower(zoom)); | |
| if (availableZooms.contains(zoom)) { | |
| return zoom; | |
| } | |
| Integer higher = availableZooms.higher(zoom); | |
| return higher != null ? higher : availableZooms.lower(zoom); |
Contributor
Author
There was a problem hiding this comment.
Agreed. I had taken the code from getClosestAvailableImageData(), where the implementation already existed (without the special case for no handle existing yet). It became so complex when we added the case for a handle with the required zoom potentially existing already (before is was just a higher->orElse->lower implementation).
Anyway, I have extracted the functionality into a shared method inside the ImageHandleManager now and there implemented it exactly as you have proposed.
HeikoKlare
force-pushed
the
fix-issue-3442
branch
from
July 27, 2026 16:28
dfd4a4b to
753929f
Compare
Drawing a blank (empty) image via GC.drawImage() with a scaled source/destination region failed with a NullPointerException. The nearest-zoom lookup tried to derive the zoom from an existing image handle, but an empty image has no handle yet, so the lookup resolved to null. The nearest-zoom lookup now falls back to using an empty image at 100% zoom when no image handle exists yet, so drawing an empty image succeeds. Adds an OS-independent GC test that draws an empty image with a scaled region to guard against this regression. Fixes eclipse-platform#3442 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
HeikoKlare
force-pushed
the
fix-issue-3442
branch
from
July 27, 2026 16:29
753929f to
281a2e1
Compare
HeikoKlare
added a commit
to HeikoKlare/www.eclipse.org-eclipse
that referenced
this pull request
Aug 3, 2026
HeikoKlare
added a commit
to HeikoKlare/www.eclipse.org-eclipse
that referenced
this pull request
Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes drawing an empty (blank)
ImageviaGC.drawImage()with a scaled source/destination region.Problem
Drawing a blank image with a scaled region failed with a
NullPointerException. The nearest-zoom lookup inPlainImageProviderWrappertried to derive the zoom from an existing image handle, but an empty image has no handle yet, so the lookup resolved tonull.Reproducible with the updated
Snippet6taken from the issue.Fix
The nearest-zoom lookup now falls back to using an empty image at 100% zoom when no image handle exists yet, so drawing an empty image succeeds.
Test
Adds an OS-independent test to
Test_org_eclipse_swt_graphics_GCthat draws an empty image with a scaled region to guard against this regression.Fixes #3442