From da98e67345a0d86bcf5fa16e5167ee074a9a8ee8 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 28 Jul 2020 14:02:46 +0900 Subject: [PATCH] mipmap: Bug fix: Wrong level calculation when the indices are empty Fixes #1269 --- image_test.go | 11 +++++++++++ internal/mipmap/mipmap.go | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/image_test.go b/image_test.go index e55fa3869..e5484df1d 100644 --- a/image_test.go +++ b/image_test.go @@ -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) +} diff --git a/internal/mipmap/mipmap.go b/internal/mipmap/mipmap.go index 1d8e58b45..c4ffc395c 100644 --- a/internal/mipmap/mipmap.go +++ b/internal/mipmap/mipmap.go @@ -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() {