graphics: DrawImage always returns nil (#331)

This commit is contained in:
Hajime Hoshi 2017-03-04 01:33:43 +09:00
parent 6ca71c6931
commit b567a07d5f
3 changed files with 14 additions and 11 deletions

View File

@ -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

View File

@ -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.

View File

@ -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 {