vbo: clamp DrawElements start/end to max possible values
authorBrian Paul <brianp@vmware.com>
Tue, 26 Jan 2010 19:47:51 +0000 (12:47 -0700)
committerBrian Paul <brianp@vmware.com>
Tue, 26 Jan 2010 19:47:54 +0000 (12:47 -0700)
Some apps are sloppy with their start/end values.  Clamp them to
max possible values to prevent problems later.

src/mesa/vbo/vbo_exec_array.c

index 2c82f7c9c5c676661f1318b7e4e80edf7e49d4c2..f4553825921cee12e504736676154c4088ed962e 100644 (file)
@@ -688,6 +688,16 @@ vbo_exec_DrawRangeElementsBaseVertex(GLenum mode,
     * or we can read/write out of memory in several different places!
     */
 
+   /* Catch/fix some potential user errors */
+   if (type == GL_UNSIGNED_BYTE) {
+      start = MIN2(start, 0xff);
+      end = MIN2(end, 0xff);
+   }
+   else if (type == GL_UNSIGNED_SHORT) {
+      start = MIN2(start, 0xffff);
+      end = MIN2(end, 0xffff);
+   }
+
    if (end >= ctx->Array.ArrayObj->_MaxElement) {
       /* the max element is out of bounds of one or more enabled arrays */
       warnCount++;