ebiten: Check the source images are not disposed at DrawTriangles and DrawTrianglesWithShader

This commit is contained in:
Hajime Hoshi 2020-06-13 18:12:21 +09:00
parent 3566dddfbf
commit 5db4a55a07
2 changed files with 35 additions and 0 deletions

View File

@ -277,6 +277,9 @@ const MaxIndicesNum = graphics.IndicesNum
func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, options *DrawTrianglesOptions) {
i.copyCheck()
if img.isDisposed() {
panic("ebiten: the given image to DrawTriangles must not be disposed")
}
if i.isDisposed() {
return
}
@ -338,6 +341,7 @@ type DrawTrianglesWithShaderOptions struct {
CompositeMode CompositeMode
}
// TODO: Add comments and tests
func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, shader *Shader, options *DrawTrianglesWithShaderOptions) {
i.copyCheck()
@ -367,6 +371,9 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha
for _, v := range options.Uniforms {
switch v := v.(type) {
case *Image:
if v.isDisposed() {
panic("ebiten: the given image to DrawTriangles must not be disposed")
}
us = append(us, v.buffered)
if firstImage == nil {
firstImage = v

View File

@ -2028,3 +2028,31 @@ func TestImageDrawOver(t *testing.T) {
}
}
}
func TestImageDrawDisposedImage(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("DrawImage must panic but not")
}
}()
dst, _ := NewImage(16, 16, FilterNearest)
src, _ := NewImage(16, 16, FilterNearest)
src.Dispose()
dst.DrawImage(src, nil)
}
func TestImageDrawTrianglesDisposedImage(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("DrawTriangles must panic but not")
}
}()
dst, _ := NewImage(16, 16, FilterNearest)
src, _ := NewImage(16, 16, FilterNearest)
src.Dispose()
vs := make([]Vertex, 4)
is := []uint16{0, 1, 2, 1, 2, 3}
dst.DrawTriangles(vs, is, src, nil)
}