Skip to content

Commit

Permalink
ebiten: bug fix: SubImage+At didn't consider the original image's set…
Browse files Browse the repository at this point in the history
…VerticesCache

Close #2428
  • Loading branch information
hajimehoshi committed Nov 2, 2022
1 parent b983014 commit aecbf23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,9 @@ func (i *Image) at(x, y int) (r, g, b, a byte) {
return 0, 0, 0, 0
}
x, y = i.adjustPosition(x, y)
if i.isSubImage() {
i = i.original
}
if c, ok := i.setVerticesCache[[2]int{x, y}]; ok {
return c[0], c[1], c[2], c[3]
}
Expand Down
12 changes: 12 additions & 0 deletions image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3433,3 +3433,15 @@ func TestImageTooManyConstantBuffersInDirectX(t *testing.T) {
t.Errorf("got: %v, want: %v", got, want)
}
}

// Issue #2428
func TestImageSetAndSubImage(t *testing.T) {
const w, h = 16, 16
img := ebiten.NewImage(w, h)
img.Set(1, 1, color.RGBA{0xff, 0, 0, 0xff})
got := img.SubImage(image.Rect(0, 0, w, h)).At(1, 1).(color.RGBA)
want := color.RGBA{0xff, 0, 0, 0xff}
if got != want {
t.Errorf("got: %v, want: %v", got, want)
}
}

0 comments on commit aecbf23

Please sign in to comment.