[Bf-blender-cvs] [fa542237dd0] master: GPU_select_buffer_stride_realign: fix crash when one of the rect's dimensions is 0.

mano-wii noreply at git.blender.org
Wed May 22 02:00:23 CEST 2019


Commit: fa542237dd0f7f7f64db42267de4b78df4cda94e
Author: mano-wii
Date:   Tue May 21 20:56:27 2019 -0300
Branches: master
https://developer.blender.org/rBfa542237dd0f7f7f64db42267de4b78df4cda94e

GPU_select_buffer_stride_realign: fix crash when one of the rect's dimensions is 0.

===================================================================

M	source/blender/gpu/intern/gpu_select.c

===================================================================

diff --git a/source/blender/gpu/intern/gpu_select.c b/source/blender/gpu/intern/gpu_select.c
index 010087e5536..119aed2f5ed 100644
--- a/source/blender/gpu/intern/gpu_select.c
+++ b/source/blender/gpu/intern/gpu_select.c
@@ -229,12 +229,18 @@ void GPU_select_buffer_stride_realign(const rcti *src, const rcti *dst, uint *r_
   const int dst_x = BLI_rcti_size_x(dst);
   const int dst_y = BLI_rcti_size_y(dst);
 
-  int last_px_written = dst_x * dst_y - 1;
   int last_px_id = src_x * (y + dst_y - 1) + (x + dst_x - 1);
-  const int skip = src_x - dst_x;
-
   memset(&r_buf[last_px_id + 1], 0, (src_x * src_y - (last_px_id + 1)) * sizeof(*r_buf));
 
+  if (last_px_id < 0) {
+    /* Nothing to write. */
+    BLI_assert(last_px_id == -1);
+    return;
+  }
+
+  int last_px_written = dst_x * dst_y - 1;
+  const int skip = src_x - dst_x;
+
   while (true) {
     for (int i = dst_x; i--;) {
       r_buf[last_px_id--] = r_buf[last_px_written--];



More information about the Bf-blender-cvs mailing list