util/u_draw: Skip rendering instead of aborting when excessive number of instances...
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 16 Nov 2012 17:57:38 +0000 (17:57 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Tue, 4 Dec 2012 19:35:19 +0000 (19:35 +0000)
This is a temporary hack. I believe the only way of properly fixing this
is to check buffer overflow just before fetching based on addresses,
instead of number of vertices/instances. This change simply allows tests
that stress buffer overflows to complete without asserting, and should
not affect valid rendering.

Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/auxiliary/util/u_draw.c

index 5b3c41231a2ed428f5a0b67ba1a71b31737b6122..83d9284b895c7847518b82d9f579df70ec083c16 100644 (file)
@@ -108,8 +108,15 @@ util_draw_max_index(
          else {
             /* Per-instance data. Simply make sure the state tracker didn't
              * request more instances than those that fit in the buffer */
-            assert((info->start_instance + info->instance_count)/element->instance_divisor
-                   <= (buffer_max_index + 1));
+            if ((info->start_instance + info->instance_count)/element->instance_divisor
+                > (buffer_max_index + 1)) {
+               /* FIXME: We really should stop thinking in terms of maximum
+                * indices/instances and simply start clamping against buffer
+                * size. */
+               debug_printf("%s: too many instances for vertex buffer\n",
+                            __FUNCTION__);
+               return 0;
+            }
          }
       }
    }