buffered: Bug fix: Set and some functions before the main loop caused wrong results

invalidatePendingPixels was not called properly.

Fixes #1081
This commit is contained in:
Hajime Hoshi 2020-02-16 19:01:16 +09:00
parent ccab797473
commit f32a3154de
2 changed files with 69 additions and 0 deletions

View File

@ -104,6 +104,7 @@ func (i *Image) MarkDisposed() {
delayedCommandsM.Lock()
if needsToDelayCommands {
delayedCommands = append(delayedCommands, func() {
i.invalidatePendingPixels()
i.img.MarkDisposed()
})
delayedCommandsM.Unlock()
@ -112,6 +113,7 @@ func (i *Image) MarkDisposed() {
delayedCommandsM.Unlock()
i.invalidatePendingPixels()
i.img.MarkDisposed()
}
func (i *Image) At(x, y int) (r, g, b, a byte) {
@ -176,6 +178,7 @@ func (i *Image) Fill(clr color.RGBA) {
delayedCommandsM.Lock()
if needsToDelayCommands {
delayedCommands = append(delayedCommands, func() {
i.invalidatePendingPixels()
i.img.Fill(clr)
})
delayedCommandsM.Unlock()
@ -205,6 +208,7 @@ func (i *Image) ReplacePixels(pix []byte) {
delayedCommandsM.Lock()
if needsToDelayCommands {
delayedCommands = append(delayedCommands, func() {
i.invalidatePendingPixels()
copied := make([]byte, len(pix))
copy(copied, pix)
i.img.ReplacePixels(copied)

View File

@ -141,3 +141,68 @@ func TestDrawTrianglesBeforeMain(t *testing.T) {
t.Errorf("got: %v, want: %v", got, want)
}
}
var testSetAndFillBeforeMainResult = func() testResult {
clr := color.RGBA{1, 2, 3, 4}
img, _ := ebiten.NewImage(16, 16, ebiten.FilterDefault)
img.Set(0, 0, clr)
img.Fill(color.RGBA{5, 6, 7, 8})
img.Set(1, 0, clr)
ch := make(chan color.RGBA, 1)
go func() {
runOnMainThread(func() {
ch <- img.At(0, 0).(color.RGBA)
})
}()
return testResult{
want: color.RGBA{5, 6, 7, 8},
got: ch,
}
}()
func TestSetAndFillBeforeMain(t *testing.T) {
got := <-testSetAndFillBeforeMainResult.got
want := testSetAndFillBeforeMainResult.want
if got != want {
t.Errorf("got: %v, want: %v", got, want)
}
}
var testSetAndReplacePixelsBeforeMainResult = func() testResult {
clr := color.RGBA{1, 2, 3, 4}
img, _ := ebiten.NewImage(16, 16, ebiten.FilterDefault)
img.Set(0, 0, clr)
pix := make([]byte, 4*16*16)
for i := 0; i < len(pix)/4; i++ {
pix[4*i] = 5
pix[4*i+1] = 6
pix[4*i+2] = 7
pix[4*i+3] = 8
}
img.ReplacePixels(pix)
img.Set(1, 0, clr)
ch := make(chan color.RGBA, 1)
go func() {
runOnMainThread(func() {
ch <- img.At(0, 0).(color.RGBA)
})
}()
return testResult{
want: color.RGBA{5, 6, 7, 8},
got: ch,
}
}()
func TestSetAndReplacePixelsBeforeMain(t *testing.T) {
got := <-testSetAndReplacePixelsBeforeMainResult.got
want := testSetAndReplacePixelsBeforeMainResult.want
if got != want {
t.Errorf("got: %v, want: %v", got, want)
}
}