diff options
author | mano-wii <germano.costa@ig.com.br> | 2019-03-31 21:58:29 +0300 |
---|---|---|
committer | mano-wii <germano.costa@ig.com.br> | 2019-04-01 17:53:04 +0300 |
commit | b5382c92cf9e265714862a19dbdcce1ec81e202a (patch) | |
tree | 03d22a9c1b66876ca9039ce00be62645ebedee1f /source/blender/gpu/intern | |
parent | fa6c2c7dba909e5d8a88817854b215990eea7051 (diff) |
Edit Mesh Selection: Clear out buffer that indicates out of bounds pixels.
This prevents the use of uninitialized buffer.
In addition, use `memset` instead of assigning in a loop.
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r-- | source/blender/gpu/intern/gpu_select.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/source/blender/gpu/intern/gpu_select.c b/source/blender/gpu/intern/gpu_select.c index 1cb51458cb3..875bcdcc674 100644 --- a/source/blender/gpu/intern/gpu_select.c +++ b/source/blender/gpu/intern/gpu_select.c @@ -219,32 +219,33 @@ const uint *GPU_select_buffer_near(const uint *buffer, int hits) void GPU_select_buffer_stride_realign( const rcti *src, const rcti *dst, uint *r_buf) { - const int src_x = BLI_rcti_size_x(src); - // const int src_y = BLI_rcti_size_y(src); - int dst_x = BLI_rcti_size_x(dst); - int dst_y = BLI_rcti_size_y(dst); - int x = dst->xmin - src->xmin; - int y = dst->ymin - src->ymin; + const int x = dst->xmin - src->xmin; + const int y = dst->ymin - src->ymin; BLI_assert(src->xmin <= dst->xmin && src->ymin <= dst->ymin && src->xmax >= dst->xmax && src->ymax >= dst->ymax); BLI_assert(x >= 0 && y >= 0); + const int src_x = BLI_rcti_size_x(src); + const int src_y = BLI_rcti_size_y(src); + 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; - int skip = src_x - dst_x; - while (dst_y--) { - int i; - for (i = dst_x; i--;) { + memset(&r_buf[last_px_id + 1], 0, (src_x * src_y - (last_px_id + 1)) * sizeof(*r_buf)); + + while (true) { + for (int i = dst_x; i--;) { r_buf[last_px_id--] = r_buf[last_px_written--]; } if (last_px_written < 0) { break; } - for (i = skip; i--;) { - r_buf[last_px_id--] = 0u; - } + last_px_id -= skip; + memset(&r_buf[last_px_id + 1], 0, skip * sizeof(*r_buf)); } memset(r_buf, 0, (last_px_id + 1) * sizeof(*r_buf)); } |