st/nine: Fix present_buffers allocation
authorAxel Davy <axel.davy@ens.fr>
Sat, 17 Jan 2015 12:43:38 +0000 (13:43 +0100)
committerAxel Davy <axel.davy@ens.fr>
Thu, 5 Feb 2015 23:07:19 +0000 (00:07 +0100)
If has_present_buffers was false at first,
but after a device reset, it turns true (for
example if we begin to render to a multisampled
back buffer), there was a crash due to present_buffers
being uninitialised.
This patch fixes it.

Reviewed-by: Tiziano Bacocco <tizbac2@gmail.com>
Signed-off-by: Axel Davy <axel.davy@ens.fr>
src/gallium/state_trackers/nine/swapchain9.c

index de61dad8e09eec01da247be50a9cdf55b8016e83..af6fe6e63faf6200921a8d97beee1de693113d9f 100644 (file)
@@ -271,12 +271,6 @@ NineSwapChain9_Resize( struct NineSwapChain9 *This,
         if (!bufs)
             return E_OUTOFMEMORY;
         This->buffers = bufs;
-        if (has_present_buffers) {
-            This->present_buffers = REALLOC(This->present_buffers,
-                                            This->present_buffers == NULL ? 0 : oldBufferCount * sizeof(struct pipe_resource *),
-                                            newBufferCount * sizeof(struct pipe_resource *));
-            memset(This->present_buffers, 0, newBufferCount * sizeof(struct pipe_resource *));
-        }
         This->present_handles = REALLOC(This->present_handles,
                                         oldBufferCount * sizeof(D3DWindowBuffer *),
                                         newBufferCount * sizeof(D3DWindowBuffer *));
@@ -286,6 +280,15 @@ NineSwapChain9_Resize( struct NineSwapChain9 *This,
         }
     }
 
+    if (has_present_buffers &&
+        (newBufferCount != oldBufferCount || !This->present_buffers)) {
+        This->present_buffers = REALLOC(This->present_buffers,
+                                        This->present_buffers == NULL ? 0 :
+                                        oldBufferCount * sizeof(struct pipe_resource *),
+                                        newBufferCount * sizeof(struct pipe_resource *));
+        memset(This->present_buffers, 0, newBufferCount * sizeof(struct pipe_resource *));
+    }
+
     for (i = 0; i < newBufferCount; ++i) {
         tmplt.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_TRANSFER_READ |
                      PIPE_BIND_TRANSFER_WRITE | PIPE_BIND_RENDER_TARGET;