From 34843a855e6b45cffbc0cd0ffae2d688e6ee1168 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 14 Sep 2015 12:51:04 +0200 Subject: Fix T46099: snapping failed on objects with some NULL-dimension in their bbox. Added a helper that ensures a bbox has some non-NULL dimension along all its axes. Also, fixed some (rather unlikely) NULL dereference cases (though it should not in this context, `BKE_object_boundbox_get()` can return NULL). --- source/blender/editors/transform/transform_snap.c | 26 +++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'source/blender/editors/transform/transform_snap.c') diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 867e862017f..f6040732983 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -1527,8 +1527,17 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes if (do_bb) { BoundBox *bb = BKE_object_boundbox_get(ob); - if (!BKE_boundbox_ray_hit_check(bb, ray_start_local, ray_normal_local, &len_diff)) { - return retval; + + if (bb) { + BoundBox bb_temp; + + /* We cannot aford a bbox with some null dimension, which may happen in some cases... + * Threshold is rather high, but seems to be needed to get good behavior, see T46099. */ + bb = BKE_boundbox_ensure_minimum_dimensions(bb, &bb_temp, 1e-1f); + + if (!BKE_boundbox_ray_hit_check(bb, ray_start_local, ray_normal_local, &len_diff)) { + return retval; + } } } else if (do_ray_start_correction) { @@ -2151,8 +2160,17 @@ static bool peelDerivedMesh( * test against boundbox first * */ if (looptri_num > 16) { - struct BoundBox *bb = BKE_object_boundbox_get(ob); - test = BKE_boundbox_ray_hit_check(bb, ray_start_local, ray_normal_local, NULL); + BoundBox *bb = BKE_object_boundbox_get(ob); + + if (bb) { + BoundBox bb_temp; + + /* We cannot aford a bbox with some null dimension, which may happen in some cases... + * Threshold is rather high, but seems to be needed to get good behavior, see T46099. */ + bb = BKE_boundbox_ensure_minimum_dimensions(bb, &bb_temp, 1e-1f); + + test = BKE_boundbox_ray_hit_check(bb, ray_start_local, ray_normal_local, NULL); + } } if (test == true) { -- cgit v1.2.3