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
This commit is contained in:
Hajime Hoshi 2022-09-13 06:09:29 -07:00
parent 40362aa62d
commit 243c224003
2 changed files with 4 additions and 8 deletions

View File

@ -337,7 +337,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(image.Rect(0, 0, i.width, i.height))
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) {