mipmap: Bug fix: Wrong level calculation when the indices are empty

Fixes #1269
This commit is contained in:
Hajime Hoshi 2020-07-28 14:02:46 +09:00
parent a43efb66b2
commit da98e67345
2 changed files with 18 additions and 0 deletions

View File

@ -2227,3 +2227,14 @@ func TestImageCompositeModeMultiply(t *testing.T) {
}
}
}
// Issue #1269
func TestImageEmptyTriangle(t *testing.T) {
const w, h = 16, 16
dst, _ := NewImage(w, h, FilterDefault)
src, _ := NewImage(1, 1, FilterDefault)
vs := []Vertex{}
is := []uint16{}
dst.DrawTriangles(vs, is, src, nil)
}

View File

@ -91,6 +91,10 @@ func (m *Mipmap) Pixels(x, y, width, height int) ([]byte, error) {
}
func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderImageNum]*Mipmap, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, canSkipMipmap bool) {
if len(indices) == 0 {
return
}
level := 0
// TODO: Do we need to check all the sources' states of being volatile?
if !canSkipMipmap && srcs[0] != nil && !srcs[0].volatile && filter != driver.FilterScreen {
@ -119,6 +123,9 @@ func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderImageNum]*Mipmap, vertices [
level = l
}
}
if level == math.MaxInt32 {
panic("mipmap: level must be calculated at least once but not")
}
}
if colorm != nil && colorm.ScaleOnly() {