diff options
author | Brian Paul <[email protected]> | 2011-11-12 11:50:32 -0700 |
---|---|---|
committer | Brian Paul <[email protected]> | 2011-11-15 07:49:26 -0700 |
commit | 438d7ac146dc89d1c2943610c662c57e11a47382 (patch) | |
tree | 4012cac294434d0238323f80e479f98d832fe41a /src/gallium/auxiliary/util | |
parent | 94780b5ee6dc118e22c29b5543c4db8e0ab1f393 (diff) |
util/draw: replace assertions with conditionals in util_draw_max_index()
Don't assert/die if a VBO is too small. Return zero instead. For
debug builds, emit a warning message since this is an unusual situation
that might indicate that there's a bug in the app.
Note that util_draw_max_index() now returns max_index+1 instead of
max_index. This lets us return zero to indicate that one of the VBOs
is too small to draw anything.
Fixes a failure with the new piglit vbo-too-small test.
Reviewed-by: José Fonseca <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r-- | src/gallium/auxiliary/util/u_draw.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/gallium/auxiliary/util/u_draw.c b/src/gallium/auxiliary/util/u_draw.c index 20837be5e59..d16575b7340 100644 --- a/src/gallium/auxiliary/util/u_draw.c +++ b/src/gallium/auxiliary/util/u_draw.c @@ -33,9 +33,13 @@ /** - * Returns the largest legal index value for the current set of bound vertex - * buffers. Regardless of any other consideration, all vertex lookups need to - * be clamped to 0..max_index to prevent an out-of-bound access. + * Returns the largest legal index value plus one for the current set + * of bound vertex buffers. Regardless of any other consideration, + * all vertex lookups need to be clamped to 0..max_index-1 to prevent + * an out-of-bound access. + * + * Note that if zero is returned it means that one or more buffers is + * too small to contain any valid vertex data. */ unsigned util_draw_max_index( @@ -48,7 +52,7 @@ util_draw_max_index( unsigned max_index; unsigned i; - max_index = ~0; + max_index = ~0U - 1; for (i = 0; i < nr_vertex_elements; i++) { const struct pipe_vertex_element *element = &vertex_elements[i]; @@ -68,13 +72,25 @@ util_draw_max_index( assert(format_desc->block.bits % 8 == 0); format_size = format_desc->block.bits/8; - assert(buffer_size - buffer->buffer_offset <= buffer_size); + if (buffer->buffer_offset >= buffer_size) { + /* buffer is too small */ + return 0; + } + buffer_size -= buffer->buffer_offset; - assert(buffer_size - element->src_offset <= buffer_size); + if (element->src_offset >= buffer_size) { + /* buffer is too small */ + return 0; + } + buffer_size -= element->src_offset; - assert(buffer_size - format_size <= buffer_size); + if (format_size > buffer_size) { + /* buffer is too small */ + return 0; + } + buffer_size -= format_size; if (buffer->stride != 0) { @@ -95,5 +111,5 @@ util_draw_max_index( } } - return max_index; + return max_index + 1; } |