From b48d501bc07727a6119d3608eee06a296769c581 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 23 Nov 2018 19:01:16 +0900 Subject: [PATCH] graphics: Explicit limitation of indices at DrawTriangles Fixes #728 --- image.go | 8 ++++++++ internal/graphicscommand/command.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/image.go b/image.go index 413261a0e..96299edb8 100644 --- a/image.go +++ b/image.go @@ -440,10 +440,15 @@ type DrawTrianglesOptions struct { Filter Filter } +// MaxIndicesNum is the maximum number of indices for DrawTriangles. +const MaxIndicesNum = graphics.IndicesNum + // DrawTriangles draws a triangle with the specified vertices and their indices. // // If len(indices) is not multiple of 3, DrawTriangles panics. // +// If len(indices) is more than MaxIndicesNum, DrawTriangles panics. +// // The rule in which DrawTriangles works effectively is same as DrawImage's. // // In contrast to DrawImage, DrawTriangles doesn't care source image edges. @@ -473,6 +478,9 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o if len(indices)%3 != 0 { panic("ebiten: len(indices) % 3 must be 0") } + if len(indices) > MaxIndicesNum { + panic("ebiten: len(indices) must be <= MaxIndicesNum") + } // TODO: Check the maximum value of indices and len(vertices)? if options == nil { diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 903e6f3f9..1321ecc4a 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -89,7 +89,7 @@ func (q *commandQueue) appendIndices(indices []uint16, offset uint16) { func (q *commandQueue) doEnqueueDrawImageCommand(dst, src *Image, nvertices, nindices int, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, forceNewCommand bool) { if nindices > graphics.IndicesNum { - panic("not implemented for too many indices") + panic("not reached") } if !forceNewCommand && 0 < len(q.commands) { if last := q.commands[len(q.commands)-1]; last.CanMerge(dst, src, color, mode, filter) {