internal/restorable: bug fix: wrong panic on mixing DrawTriangles and WritePixels

When DrawTriangles is called and then WritePixels is called on a
sub-image, a panic happened. However, this panic actually happens
only when the graphics driver requires restoring (e.g. OpenGL ES
on Android). The situation was very limited, but this was a real
problem on Android.

This panic was introduced to prevent a rendering bug by a inmature
graphics drivers, but we should no longer need this. This change
just removes the panic.

Updates #292
Closes #2346
This commit is contained in:
Hajime Hoshi 2022-09-13 06:09:29 -07:00
parent ef26267703
commit eecabf25f4
2 changed files with 4 additions and 8 deletions

View File

@ -322,7 +322,8 @@ func (i *Image) WritePixels(pixels []byte, x, y, width, height int) {
// drawTrianglesHistory and basePixels cannot be mixed. // drawTrianglesHistory and basePixels cannot be mixed.
if len(i.drawTrianglesHistory) > 0 { if len(i.drawTrianglesHistory) > 0 {
panic("restorable: WritePixels for a part after DrawTriangles is forbidden") i.makeStale()
return
} }
if i.stale { if i.stale {

View File

@ -801,13 +801,7 @@ func TestAllowWritePixelsAfterDrawTriangles(t *testing.T) {
// WritePixels for a whole image doesn't panic. // WritePixels for a whole image doesn't panic.
} }
func TestDisallowWritePixelsForPartAfterDrawTriangles(t *testing.T) { func TestAllowWritePixelsForPartAfterDrawTriangles(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("WritePixels for a part after DrawTriangles must panic but not")
}
}()
const w, h = 16, 16 const w, h = 16, 16
src := restorable.NewImage(w, h, restorable.ImageTypeRegular) src := restorable.NewImage(w, h, restorable.ImageTypeRegular)
dst := restorable.NewImage(w, h, restorable.ImageTypeRegular) dst := restorable.NewImage(w, h, restorable.ImageTypeRegular)
@ -822,6 +816,7 @@ func TestDisallowWritePixelsForPartAfterDrawTriangles(t *testing.T) {
} }
dst.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{src}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false) dst.DrawTriangles([graphics.ShaderImageCount]*restorable.Image{src}, [graphics.ShaderImageCount - 1][2]float32{}, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeSourceOver, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, nil, nil, false)
dst.WritePixels(make([]byte, 4), 0, 0, 1, 1) dst.WritePixels(make([]byte, 4), 0, 0, 1, 1)
// WritePixels for a part of image doesn't panic.
} }
func TestExtend(t *testing.T) { func TestExtend(t *testing.T) {