From 6a9d163ab416a7d1c44a11b75716ee32fb3c9f0b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Tue, 2 Apr 2013 16:17:34 +0200
Subject: wined3d: Don't put rectangle pointers into wined3d_cs_clear

---
 dlls/wined3d/cs.c     | 13 ++++++++-----
 dlls/wined3d/device.c |  2 ++
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index b30e62a..bac3fdb 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -95,11 +95,11 @@ struct wined3d_cs_clear
 {
     enum wined3d_cs_op opcode;
     DWORD rect_count;
-    const RECT *rects;
     DWORD flags;
     const struct wined3d_color *color;
     float depth;
     DWORD stencil;
+    RECT rects[1];
 };
 
 struct wined3d_cs_draw
@@ -448,25 +448,28 @@ static UINT wined3d_cs_exec_clear(struct wined3d_cs *cs, const void *data)
     const struct wined3d_cs_clear *op = data;
     struct wined3d_device *device;
     RECT draw_rect;
+    unsigned int extra_rects = op->rect_count ? op->rect_count - 1 : 0;
 
     device = cs->device;
     wined3d_get_draw_rect(&device->state, &draw_rect);
     device_clear_render_targets(device, device->adapter->gl_info.limits.buffers,
-            &cs->state.fb, op->rect_count, op->rects, &draw_rect, op->flags,
+            &cs->state.fb, op->rect_count, op->rect_count ? op->rects : NULL, &draw_rect, op->flags,
             op->color, op->depth, op->stencil);
 
-    return sizeof(*op);
+    return sizeof(*op) + sizeof(*op->rects) * extra_rects;
 }
 
 void wined3d_cs_emit_clear(struct wined3d_cs *cs, DWORD rect_count, const RECT *rects,
         DWORD flags, const struct wined3d_color *color, float depth, DWORD stencil)
 {
     struct wined3d_cs_clear *op;
+    unsigned int extra_rects = rect_count ? rect_count - 1 : 0;
 
-    op = cs->ops->require_space(cs, sizeof(*op));
+    op = cs->ops->require_space(cs, sizeof(*op) + sizeof(*op->rects) * extra_rects);
     op->opcode = WINED3D_CS_OP_CLEAR;
     op->rect_count = rect_count;
-    op->rects = rects;
+    if (rect_count)
+        memcpy(op->rects, rects, rect_count * sizeof(*rects));
     op->flags = flags;
     op->color = color;
     op->depth = depth;
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 08422ad..3bb3cf0 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -3292,6 +3292,8 @@ HRESULT CDECL wined3d_device_clear(struct wined3d_device *device, DWORD rect_cou
         WARN("Rects is %p, but rect_count is 0, ignoring clear\n", rects);
         return WINED3D_OK;
     }
+    if (rect_count && !rects)
+        rect_count = 0;
 
     if (flags & (WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL))
     {
-- 
2.1.3

