pixels: Bug fix: Reset pixels correctly

This commit is contained in:
Hajime Hoshi 2016-07-26 11:40:41 +09:00
parent 0fc61ed568
commit 40427b6263
2 changed files with 11 additions and 12 deletions

View File

@ -226,12 +226,18 @@ func (i *imageImpl) resetPixelsIfNeeded(target *imageImpl, context *opengl.Conte
if target.isDisposed() {
return errors.New("ebiten: target is already disposed")
}
if i.pixels == nil {
return nil
}
if !i.pixels.NeedsReset(target.image) {
return nil
}
if context == nil {
// context is null when this is not initialized yet.
i.pixels = nil
return nil
}
if err := i.pixels.ResetIfNeeded(target.image, context); err != nil {
if err := i.pixels.Reset(context); err != nil {
return err
}
return nil

View File

@ -116,21 +116,14 @@ func (p *Pixels) Reset(context *opengl.Context) error {
return nil
}
func (p *Pixels) ResetIfNeeded(target *graphics.Image, context *opengl.Context) error {
func (p *Pixels) NeedsReset(target *graphics.Image) bool {
if p.drawImageHistory == nil {
return nil
return false
}
if !p.hasHistoryWith(target) {
return nil
return false
}
var err error
p.basePixels, err = p.image.Pixels(context)
if err != nil {
return err
}
p.baseColor = nil
p.drawImageHistory = nil
return nil
return true
}
func (p *Pixels) HasHistory() bool {