mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-04 15:04:28 +01:00
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:
parent
d790c86e8a
commit
ff8689cfcd
@ -111,13 +111,14 @@ func (i *Image) MarkDisposed() {
|
|||||||
|
|
||||||
if needsToDelayCommands {
|
if needsToDelayCommands {
|
||||||
delayedCommands = append(delayedCommands, func() error {
|
delayedCommands = append(delayedCommands, func() error {
|
||||||
|
i.invalidatePendingPixels()
|
||||||
i.img.MarkDisposed()
|
i.img.MarkDisposed()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
i.invalidatePendingPixels()
|
i.invalidatePendingPixels()
|
||||||
|
i.img.MarkDisposed()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) At(x, y int) (r, g, b, a byte, err error) {
|
func (i *Image) At(x, y int) (r, g, b, a byte, err error) {
|
||||||
@ -187,6 +188,7 @@ func (i *Image) Fill(clr color.RGBA) {
|
|||||||
|
|
||||||
if needsToDelayCommands {
|
if needsToDelayCommands {
|
||||||
delayedCommands = append(delayedCommands, func() error {
|
delayedCommands = append(delayedCommands, func() error {
|
||||||
|
i.invalidatePendingPixels()
|
||||||
i.img.Fill(clr)
|
i.img.Fill(clr)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -203,6 +205,7 @@ func (i *Image) ReplacePixels(pix []byte) {
|
|||||||
|
|
||||||
if needsToDelayCommands {
|
if needsToDelayCommands {
|
||||||
delayedCommands = append(delayedCommands, func() error {
|
delayedCommands = append(delayedCommands, func() error {
|
||||||
|
i.invalidatePendingPixels()
|
||||||
copied := make([]byte, len(pix))
|
copied := make([]byte, len(pix))
|
||||||
copy(copied, pix)
|
copy(copied, pix)
|
||||||
i.img.ReplacePixels(copied)
|
i.img.ReplacePixels(copied)
|
||||||
|
@ -181,3 +181,68 @@ func TestDrawTrianglesBeforeMain(t *testing.T) {
|
|||||||
t.Errorf("got: %v, want: %v", got, want)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user