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) {