Skip to content

Commit

Permalink
internal/restorable: bug fix: wrong panic on mixing DrawTriangles and…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
hajimehoshi committed Sep 24, 2022
1 parent ef26267 commit eecabf2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
3 changes: 2 additions & 1 deletion internal/restorable/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ func (i *Image) WritePixels(pixels []byte, x, y, width, height int) {

// drawTrianglesHistory and basePixels cannot be mixed.
if len(i.drawTrianglesHistory) > 0 {
panic("restorable: WritePixels for a part after DrawTriangles is forbidden")
i.makeStale()
return
}

if i.stale {
Expand Down
9 changes: 2 additions & 7 deletions internal/restorable/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,13 +801,7 @@ func TestAllowWritePixelsAfterDrawTriangles(t *testing.T) {
// WritePixels for a whole image doesn't panic.
}

func TestDisallowWritePixelsForPartAfterDrawTriangles(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("WritePixels for a part after DrawTriangles must panic but not")
}
}()

func TestAllowWritePixelsForPartAfterDrawTriangles(t *testing.T) {
const w, h = 16, 16
src := restorable.NewImage(w, h, restorable.ImageTypeRegular)
dst := restorable.NewImage(w, h, restorable.ImageTypeRegular)
Expand All @@ -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.WritePixels(make([]byte, 4), 0, 0, 1, 1)
// WritePixels for a part of image doesn't panic.
}

func TestExtend(t *testing.T) {
Expand Down

0 comments on commit eecabf2

Please sign in to comment.