mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
ebiten: Check the source images are not disposed at DrawTriangles and DrawTrianglesWithShader
This commit is contained in:
parent
3566dddfbf
commit
5db4a55a07
7
image.go
7
image.go
@ -277,6 +277,9 @@ const MaxIndicesNum = graphics.IndicesNum
|
|||||||
func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, options *DrawTrianglesOptions) {
|
func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, options *DrawTrianglesOptions) {
|
||||||
i.copyCheck()
|
i.copyCheck()
|
||||||
|
|
||||||
|
if img.isDisposed() {
|
||||||
|
panic("ebiten: the given image to DrawTriangles must not be disposed")
|
||||||
|
}
|
||||||
if i.isDisposed() {
|
if i.isDisposed() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -338,6 +341,7 @@ type DrawTrianglesWithShaderOptions struct {
|
|||||||
CompositeMode CompositeMode
|
CompositeMode CompositeMode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Add comments and tests
|
||||||
func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, shader *Shader, options *DrawTrianglesWithShaderOptions) {
|
func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, shader *Shader, options *DrawTrianglesWithShaderOptions) {
|
||||||
i.copyCheck()
|
i.copyCheck()
|
||||||
|
|
||||||
@ -367,6 +371,9 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha
|
|||||||
for _, v := range options.Uniforms {
|
for _, v := range options.Uniforms {
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
case *Image:
|
case *Image:
|
||||||
|
if v.isDisposed() {
|
||||||
|
panic("ebiten: the given image to DrawTriangles must not be disposed")
|
||||||
|
}
|
||||||
us = append(us, v.buffered)
|
us = append(us, v.buffered)
|
||||||
if firstImage == nil {
|
if firstImage == nil {
|
||||||
firstImage = v
|
firstImage = v
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user