mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
buffered: Bug fix: Copying pixels failed for the delayed commands
Fixes #1082
This commit is contained in:
parent
f32a3154de
commit
760df0353b
@ -222,6 +222,9 @@ func (i *Image) ReplacePixels(pix []byte) {
|
||||
i.img.ReplacePixels(pix)
|
||||
}
|
||||
|
||||
// DrawTriangles draws the src image with the given vertices.
|
||||
//
|
||||
// Copying vertices and indices is the caller's responsibility.
|
||||
func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) {
|
||||
if i == src {
|
||||
panic("buffered: Image.DrawTriangles: src must be different from the receiver")
|
||||
@ -232,6 +235,7 @@ func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16,
|
||||
delayedCommands = append(delayedCommands, func() {
|
||||
src.resolvePendingPixels(true)
|
||||
i.resolvePendingPixels(false)
|
||||
// Arguments are not copied. Copying is the caller's responsibility.
|
||||
i.img.DrawTriangles(src.img, vertices, indices, colorm, mode, filter, address)
|
||||
})
|
||||
delayedCommandsM.Unlock()
|
||||
|
@ -206,3 +206,43 @@ func TestSetAndReplacePixelsBeforeMain(t *testing.T) {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
var testReplacePixelsAndModifyBeforeMainResult = func() testResult {
|
||||
img, _ := ebiten.NewImage(16, 16, ebiten.FilterDefault)
|
||||
pix := make([]byte, 4*16*16)
|
||||
for i := 0; i < len(pix)/4; i++ {
|
||||
pix[4*i] = 1
|
||||
pix[4*i+1] = 2
|
||||
pix[4*i+2] = 3
|
||||
pix[4*i+3] = 4
|
||||
}
|
||||
img.ReplacePixels(pix)
|
||||
// After calling ReplacePixels, modifying pix must not affect the result.
|
||||
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
|
||||
}
|
||||
|
||||
ch := make(chan color.RGBA, 1)
|
||||
go func() {
|
||||
runOnMainThread(func() {
|
||||
ch <- img.At(0, 0).(color.RGBA)
|
||||
})
|
||||
}()
|
||||
|
||||
return testResult{
|
||||
want: color.RGBA{1, 2, 3, 4},
|
||||
got: ch,
|
||||
}
|
||||
}()
|
||||
|
||||
func TestReplacePixelsAndModifyBeforeMain(t *testing.T) {
|
||||
got := <-testReplacePixelsAndModifyBeforeMainResult.got
|
||||
want := testReplacePixelsAndModifyBeforeMainResult.want
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user