mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Bug fix: NewImageFromImage with ebiten.Image froze (#212)
This commit is contained in:
parent
c21d53a3b7
commit
9d278e3cca
5
image.go
5
image.go
@ -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()
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user