graphics: Bug fix: (*Image).At must return color.RGBA type value

This commit is contained in:
Hajime Hoshi 2018-03-03 18:51:52 +09:00
parent 046a6cd014
commit d5bca2d499
2 changed files with 11 additions and 2 deletions

View File

@ -250,12 +250,12 @@ func (i *Image) ColorModel() color.Model {
//
// At loads pixels from GPU to system memory if necessary, which means that At can be slow.
//
// At always returns color.Transparend if the image is disposed.
// At always returns a transparent color if the image is disposed.
//
// At can't be called before the main loop (ebiten.Run) starts (as of version 1.4.0-alpha).
func (i *Image) At(x, y int) color.Color {
if i.isDisposed() {
return color.Transparent
return color.RGBA{}
}
// TODO: Error should be delayed until flushing. Do not panic here.
clr, err := i.restorable.At(x, y)

View File

@ -378,9 +378,18 @@ func TestImageDispose(t *testing.T) {
t.Fatal(err)
return
}
img.Fill(color.White)
if err := img.Dispose(); err != nil {
t.Errorf("img.Dipose() returns error: %v", err)
}
// The color is transparent (color.RGBA{}).
// Note that the value's type must be color.RGBA.
got := img.At(0, 0)
want := color.RGBA{}
if got != want {
t.Errorf("img.At(0, 0) got: %v, want: %v", got, want)
}
}
func min(a, b int) int {