mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
graphics: DrawImage always returns nil (#331)
This commit is contained in:
parent
6ca71c6931
commit
b567a07d5f
@ -164,9 +164,7 @@ func (c *graphicsContext) UpdateAndDraw(context *opengl.Context, updateCount int
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for i := 0; i < updateCount; i++ {
|
for i := 0; i < updateCount; i++ {
|
||||||
if err := theImagesForRestoring.clearVolatileImages(); err != nil {
|
theImagesForRestoring.clearVolatileImages()
|
||||||
return err
|
|
||||||
}
|
|
||||||
setRunningSlowly(i < updateCount-1)
|
setRunningSlowly(i < updateCount-1)
|
||||||
if err := c.f(c.offscreen); err != nil {
|
if err := c.f(c.offscreen); err != nil {
|
||||||
return err
|
return err
|
||||||
|
12
image.go
12
image.go
@ -121,13 +121,12 @@ func (i *images) restore(context *opengl.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *images) clearVolatileImages() error {
|
func (i *images) clearVolatileImages() {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
for img := range i.images {
|
for img := range i.images {
|
||||||
img.clearIfVolatile()
|
img.clearIfVolatile()
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Image represents an image.
|
// 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,
|
// Even if the argument image is mutated after this call,
|
||||||
// the drawing result is never affected.
|
// 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.
|
// This function is concurrent-safe.
|
||||||
func (i *Image) DrawImage(image *Image, options *DrawImageOptions) error {
|
func (i *Image) DrawImage(image *Image, options *DrawImageOptions) error {
|
||||||
theImagesForRestoring.resetPixelsIfDependingOn(i, glContext())
|
theImagesForRestoring.resetPixelsIfDependingOn(i, glContext())
|
||||||
return i.impl.DrawImage(image, options)
|
i.impl.DrawImage(image, options)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bounds returns the bounds of the image.
|
// Bounds returns the bounds of the image.
|
||||||
|
@ -84,7 +84,7 @@ func (i *imageImpl) clearIfVolatile() {
|
|||||||
i.restorable.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
|
// Calculate vertices before locking because the user can do anything in
|
||||||
// options.ImageParts interface without deadlock (e.g. Call Image functions).
|
// options.ImageParts interface without deadlock (e.g. Call Image functions).
|
||||||
if options == nil {
|
if options == nil {
|
||||||
@ -104,19 +104,18 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
|||||||
w, h := image.impl.restorable.Size()
|
w, h := image.impl.restorable.Size()
|
||||||
vs := vertices(parts, w, h, &options.GeoM.impl)
|
vs := vertices(parts, w, h, &options.GeoM.impl)
|
||||||
if len(vs) == 0 {
|
if len(vs) == 0 {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
if i == image.impl {
|
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()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
if i.restorable == nil {
|
if i.restorable == nil {
|
||||||
return errors.New("ebiten: image is already disposed")
|
return
|
||||||
}
|
}
|
||||||
mode := opengl.CompositeMode(options.CompositeMode)
|
mode := opengl.CompositeMode(options.CompositeMode)
|
||||||
i.restorable.DrawImage(image.impl.restorable, vs, options.ColorM.impl, mode)
|
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 {
|
func (i *imageImpl) At(x, y int, context *opengl.Context) color.Color {
|
||||||
|
Loading…
Reference in New Issue
Block a user