diff --git a/graphicscontext.go b/graphicscontext.go index f3e6584b9..e6ab20716 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -164,9 +164,7 @@ func (c *graphicsContext) UpdateAndDraw(context *opengl.Context, updateCount int return err } for i := 0; i < updateCount; i++ { - if err := theImagesForRestoring.clearVolatileImages(); err != nil { - return err - } + theImagesForRestoring.clearVolatileImages() setRunningSlowly(i < updateCount-1) if err := c.f(c.offscreen); err != nil { return err diff --git a/image.go b/image.go index 30d2e61aa..9f0a0ed9c 100644 --- a/image.go +++ b/image.go @@ -121,13 +121,12 @@ func (i *images) restore(context *opengl.Context) error { return nil } -func (i *images) clearVolatileImages() error { +func (i *images) clearVolatileImages() { i.m.Lock() defer i.m.Unlock() for img := range i.images { img.clearIfVolatile() } - return nil } // Image represents an image. @@ -187,10 +186,17 @@ func (i *Image) Fill(clr color.Color) error { // Even if the argument image is mutated after this call, // the drawing result is never affected. // +// When the image is disposed, DrawImage does nothing. +// +// When image is as same as i, DrawImage panics. +// +// DrawImage always returns nil as of 1.5.0-alpha. +// // This function is concurrent-safe. func (i *Image) DrawImage(image *Image, options *DrawImageOptions) error { theImagesForRestoring.resetPixelsIfDependingOn(i, glContext()) - return i.impl.DrawImage(image, options) + i.impl.DrawImage(image, options) + return nil } // Bounds returns the bounds of the image. diff --git a/imageimpl.go b/imageimpl.go index ebc9640a4..517526001 100644 --- a/imageimpl.go +++ b/imageimpl.go @@ -84,7 +84,7 @@ func (i *imageImpl) clearIfVolatile() { i.restorable.ClearIfVolatile() } -func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error { +func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) { // Calculate vertices before locking because the user can do anything in // options.ImageParts interface without deadlock (e.g. Call Image functions). if options == nil { @@ -104,19 +104,18 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error { w, h := image.impl.restorable.Size() vs := vertices(parts, w, h, &options.GeoM.impl) if len(vs) == 0 { - return nil + return } if i == image.impl { - return errors.New("ebiten: Image.DrawImage: image should be different from the receiver") + panic("ebiten: Image.DrawImage: image must be different from the receiver") } i.m.Lock() defer i.m.Unlock() if i.restorable == nil { - return errors.New("ebiten: image is already disposed") + return } mode := opengl.CompositeMode(options.CompositeMode) i.restorable.DrawImage(image.impl.restorable, vs, options.ColorM.impl, mode) - return nil } func (i *imageImpl) At(x, y int, context *opengl.Context) color.Color {