softpipe: fix set_framebuffer_state with uninitialized surfaces past nr_cbufs-1
authorMarek Olšák <maraeo@gmail.com>
Wed, 12 Sep 2012 22:46:54 +0000 (00:46 +0200)
committerMarek Olšák <maraeo@gmail.com>
Sun, 30 Sep 2012 16:57:56 +0000 (18:57 +0200)
Tested-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/drivers/softpipe/sp_state_surface.c

index 2db6faeca465ae838193f20a33f7b4c19f852781..c0bd1f757e1d891f8e3adfaf7bb9a06fed857aa0 100644 (file)
@@ -54,16 +54,18 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe,
    draw_flush(sp->draw);
 
    for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
+      struct pipe_surface *cb = i < fb->nr_cbufs ? fb->cbufs[i] : NULL;
+
       /* check if changing cbuf */
-      if (sp->framebuffer.cbufs[i] != fb->cbufs[i]) {
+      if (sp->framebuffer.cbufs[i] != cb) {
          /* flush old */
          sp_flush_tile_cache(sp->cbuf_cache[i]);
 
          /* assign new */
-         pipe_surface_reference(&sp->framebuffer.cbufs[i], fb->cbufs[i]);
+         pipe_surface_reference(&sp->framebuffer.cbufs[i], cb);
 
          /* update cache */
-         sp_tile_cache_set_surface(sp->cbuf_cache[i], fb->cbufs[i]);
+         sp_tile_cache_set_surface(sp->cbuf_cache[i], cb);
       }
    }