i965: Fix software primitive restart with indirect draws.
authorKenneth Graunke <kenneth@whitecape.org>
Sat, 11 Apr 2015 09:21:48 +0000 (02:21 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Tue, 14 Apr 2015 08:49:02 +0000 (01:49 -0700)
new_prim was declared as a stack variable within a nested scope; we
tried to retain a pointer to that data beyond the scope, which is bogus.

GCC with -O1 eliminated most of the code that set new_prim's fields.

Move the declaration to fix the bug.

v2: Also fix new_ib (thanks to Matt Turner and Ben Widawsky).

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=81025
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Ben Widawsky <ben@bwidawsk.net>
Cc: mesa-stable@lists.freedesktop.org
src/mesa/vbo/vbo_primitive_restart.c

index 562dedcd5c99f45901179ce547b21ab93d559ef3..dafc4fd2a9aca80e4bbdad5ae224b5ddb4b95c15 100644 (file)
@@ -167,6 +167,8 @@ vbo_sw_primitive_restart(struct gl_context *ctx,
                          struct gl_buffer_object *indirect)
 {
    GLuint prim_num;
+   struct _mesa_prim new_prim;
+   struct _mesa_index_buffer new_ib;
    struct sub_primitive *sub_prims;
    struct sub_primitive *sub_prim;
    GLuint num_sub_prims;
@@ -182,8 +184,6 @@ vbo_sw_primitive_restart(struct gl_context *ctx,
 
    /* If there is an indirect buffer, map it and extract the draw params */
    if (indirect && prims[0].is_indirect) {
-      struct _mesa_prim new_prim = *prims;
-      struct _mesa_index_buffer new_ib = *ib;
       const uint32_t *indirect_params;
       if (!ctx->Driver.MapBufferRange(ctx, 0, indirect->Size, GL_MAP_READ_BIT,
                                       indirect, MAP_INTERNAL)) {
@@ -195,6 +195,7 @@ vbo_sw_primitive_restart(struct gl_context *ctx,
       }
 
       assert(nr_prims == 1);
+      new_prim = prims[0];
       indirect_params = (const uint32_t *)
                         ADD_POINTERS(indirect->Mappings[MAP_INTERNAL].Pointer,
                                      new_prim.indirect_offset);
@@ -206,6 +207,7 @@ vbo_sw_primitive_restart(struct gl_context *ctx,
       new_prim.basevertex = indirect_params[3];
       new_prim.base_instance = indirect_params[4];
 
+      new_ib = *ib;
       new_ib.count = new_prim.count;
 
       prims = &new_prim;