graphics: Bug fix: NewImageFromImage with ebiten.Image froze (#212)

This commit is contained in:
Hajime Hoshi 2016-05-12 02:00:22 +09:00
parent c21d53a3b7
commit 9d278e3cca
2 changed files with 16 additions and 0 deletions

View File

@ -277,6 +277,11 @@ func NewImage(width, height int, filter Filter) (*Image, error) {
//
// This function is concurrent-safe.
func NewImageFromImage(img image.Image, filter Filter) (*Image, error) {
// Can't call (*ebiten.Image).At here because of the lock.
if _, ok := img.(*Image); ok {
return nil, errors.New("ebiten: NewImageFromImage can't take *ebiten.Image")
}
imageM.Lock()
defer imageM.Unlock()

View File

@ -278,4 +278,15 @@ func TestImageCompositeModeLighter(t *testing.T) {
}
}
func TestNewImageFromEbitenImage(t *testing.T) {
img, _, err := openEbitenImage("testdata/ebiten.png")
if err != nil {
t.Fatal(err)
return
}
if _, err := NewImageFromImage(img, FilterNearest); err == nil {
t.Errorf("NewImageFromImage with an *ebiten.Image must return an error")
}
}
// TODO: Add more tests (e.g. DrawImage with color matrix)