mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
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:
parent
40362aa62d
commit
243c224003
@ -337,7 +337,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(image.Rect(0, 0, i.width, i.height))
|
||||
return
|
||||
}
|
||||
|
||||
if i.stale {
|
||||
|
@ -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)
|
||||
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user