diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 00508e288..3b9f02630 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -215,6 +215,7 @@ func quadVertices(dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1, cr, cg, cb, ca float32 // Fill fills the specified part of the image with a solid color. func (i *Image) Fill(clr color.RGBA) { + theImages.makeStaleIfDependingOn(i) i.basePixels = Pixels{ baseColor: clr, } diff --git a/internal/restorable/images_test.go b/internal/restorable/images_test.go index 8c215526c..2716a5879 100644 --- a/internal/restorable/images_test.go +++ b/internal/restorable/images_test.go @@ -819,6 +819,38 @@ func TestFill(t *testing.T) { } } +// Issue #1170 +func TestFill2(t *testing.T) { + const w, h = 16, 16 + src := NewImage(w, h, false) + src.Fill(color.RGBA{0xff, 0, 0, 0xff}) + + dst := NewImage(w, h, false) + vs := quadVertices(w, h, 0, 0) + is := graphics.QuadIndices() + dst.DrawTriangles(src, vs, is, nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressClampToZero, nil, nil) + + // Fill src with a different color. This should not affect dst. + src.Fill(color.RGBA{0, 0xff, 0, 0xff}) + + if err := ResolveStaleImages(); err != nil { + t.Fatal(err) + } + if err := RestoreIfNeeded(); err != nil { + t.Fatal(err) + } + + for j := 0; j < h; j++ { + for i := 0; i < w; i++ { + got := pixelsToColor(dst.BasePixelsForTesting(), i, j) + want := color.RGBA{0xff, 0, 0, 0xff} + if got != want { + t.Errorf("img.At(%d, %d): got: %v, want: %v", i, j, got, want) + } + } + } +} + func TestMutateSlices(t *testing.T) { const w, h = 16, 16 dst := NewImage(w, h, false)