Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGermano Cavalcante <germano.costa@ig.com.br>2021-04-17 19:51:33 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2021-04-17 19:52:31 +0300
commite4990a565884687c1750151316dc2561daae4216 (patch)
tree0a12ce46ff27a3263eb7bd8a638274873be6bf65 /source/blender/editors/space_view3d/view3d_utils.c
parentd0d85742fc16aedb8e2145ca76fa77bd47ec2e54 (diff)
Fix wrong logic used in 'ED_view3d_depth_read_cached'
It is important to limit the pixels read on `BLI_array_iter_spiral_square`. Fortunately `ED_view3d_depth_read_cached` was not being called with a `margin` parameter. Wrong logic introduced in rB44c76e4ce310.
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_utils.c')
-rw-r--r--source/blender/editors/space_view3d/view3d_utils.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c
index fde98c18803..f96c17d7cff 100644
--- a/source/blender/editors/space_view3d/view3d_utils.c
+++ b/source/blender/editors/space_view3d/view3d_utils.c
@@ -1630,12 +1630,23 @@ bool ED_view3d_camera_to_view_selected(struct Main *bmain,
/** \name Depth Buffer Utilities
* \{ */
+struct ReadData {
+ int count;
+ int count_max;
+ float r_depth;
+};
+
static bool depth_read_test_fn(const void *value, void *userdata)
{
- float *r_depth = userdata;
+ struct ReadData *data = userdata;
float depth = *(float *)value;
- if (depth < *r_depth) {
- *r_depth = depth;
+ if (depth < data->r_depth) {
+ data->r_depth = depth;
+ }
+
+ if ((++data->count) >= data->count_max) {
+ /* Outside the margin. */
+ return true;
}
return false;
}
@@ -1657,9 +1668,18 @@ bool ED_view3d_depth_read_cached(const ViewDepths *vd,
float depth = 1.0f;
if (margin) {
- /* TODO: No need to go spiral. */
int shape[2] = {vd->w, vd->h};
- BLI_array_iter_spiral_square(vd->depths, shape, mval, depth_read_test_fn, &depth);
+ int pixel_count = (min_ii(x + margin + 1, shape[1]) - max_ii(x - margin, 0)) *
+ (min_ii(y + margin + 1, shape[0]) - max_ii(y - margin, 0));
+
+ struct ReadData data;
+ data.count = 0;
+ data.count_max = pixel_count;
+ data.r_depth = 1.0f;
+
+ /* TODO: No need to go spiral. */
+ BLI_array_iter_spiral_square(vd->depths, shape, mval, depth_read_test_fn, &data);
+ depth = data.r_depth;
}
else {
depth = vd->depths[y * vd->w + x];