graphics: Panic first when drawing the same image

This commit is contained in:
Hajime Hoshi 2017-05-30 00:56:01 +09:00
parent e794ab71ff
commit c6c8ff22d7

View File

@ -90,10 +90,13 @@ func (i *Image) Fill(clr color.Color) error {
// //
// When the image is disposed, DrawImage does nothing. // When the image is disposed, DrawImage does nothing.
// //
// When image is as same as i, DrawImage panics. // When the given image is as same as i, DrawImage panics.
// //
// DrawImage always returns nil as of 1.5.0-alpha. // DrawImage always returns nil as of 1.5.0-alpha.
func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error { func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
if i == img {
panic("ebiten: Image.DrawImage: img must be different from the receiver")
}
if i.restorable == nil { if i.restorable == nil {
return nil return nil
} }
@ -137,9 +140,6 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
sy1 = r.Max.Y sy1 = r.Max.Y
} }
vs := vertices(sx0, sy0, sx1, sy1, w, h, &options.GeoM.impl) vs := vertices(sx0, sy0, sx1, sy1, w, h, &options.GeoM.impl)
if i == img {
panic("ebiten: Image.DrawImage: img must be different from the receiver")
}
mode := opengl.CompositeMode(options.CompositeMode) mode := opengl.CompositeMode(options.CompositeMode)
i.restorable.DrawImage(img.restorable, vs, &options.ColorM.impl, mode) i.restorable.DrawImage(img.restorable, vs, &options.ColorM.impl, mode)
return nil return nil