Skip to content

Draw a raster from the top left of its image bounds - #6496

Open
4RH1T3CT0R7 wants to merge 1 commit into
fyne-io:developfrom
4RH1T3CT0R7:fix/raster-bounds
Open

Draw a raster from the top left of its image bounds#6496
4RH1T3CT0R7 wants to merge 1 commit into
fyne-io:developfrom
4RH1T3CT0R7:fix/raster-bounds

Conversation

@4RH1T3CT0R7

@4RH1T3CT0R7 4RH1T3CT0R7 commented Aug 24, 2026

Copy link
Copy Markdown

On develop the reproducer in #6461 doesn't just draw in the wrong place, it panics, makeslice: cap out of range inside x/image/draw. When the raster and the image bounds don't overlap the generator returns an image.Uniform, and the scaler tries to allocate from its infinite bounds.

The generator was treating Bounds().Min as a position on the canvas object, so an image cut out of a sprite sheet drew shifted. It now always returns the destination image at the raster size with the source drawn in from its top left, which is the mapping @andydotxyz described on the issue. TestRasterFromImage asserted the old placement and now asserts (0, 0).

It's a behaviour change: @dweymouth suggested holding it for 3.0, @andydotxyz replied that the documentation was the wrong part. canvas.Image has the same problem and I've left it alone.

Fixes #6461

@andydotxyz

Copy link
Copy Markdown
Member

Can you rebase this on develop current to see how many of the test failures go away?

NewRasterFromImage was treating the origin of the source image bounds as
a position on the canvas object. An image cut out of a sprite sheet, or
one built with image.NewRGBA(image.Rect(150, 200, 300, 400)), was drawn
shifted by Bounds().Min - or not drawn at all when the raster happened
to be exactly the size of the image, as the painter then read from
pixels that are outside the source.

Where the two did not overlap at all the generator returned an
image.Uniform, whose infinite bounds panic the software scaler. It now
always returns the destination it allocated, so the uncovered area is
the zero pixels that image was made with.

Fixes fyne-io#6461
@4RH1T3CT0R7

Copy link
Copy Markdown
Author

Rebased onto current develop, same single commit. Let's see what CI makes of it now.

@4RH1T3CT0R7

Copy link
Copy Markdown
Author

Everything passes now except platform_tests (stable, ubuntu-latest), and that one only trips the coverage gate at the end, no test fails. develop's own run on 3c6ad39 fails the same way (https://github.com/fyne-io/fyne/actions/runs/32974081173/job/98194438933), so it doesn't look related to this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raster that was created with NewRasterFromImage renders from Bounds.Min instead of from zero

2 participants