From d5bca2d499ee776afa2acfe273b6f20920508183 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 3 Mar 2018 18:51:52 +0900 Subject: [PATCH] graphics: Bug fix: (*Image).At must return color.RGBA type value --- image.go | 4 ++-- image_test.go | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/image.go b/image.go index d6efa59ed..d6e202af6 100644 --- a/image.go +++ b/image.go @@ -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) diff --git a/image_test.go b/image_test.go index a1cadcbc3..b32c1ced8 100644 --- a/image_test.go +++ b/image_test.go @@ -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 {