[Bf-blender-cvs] [daa4d4dd258] master: Fix T62248: Infinite Hotspot Size Crop Node

Jeroen Bakker noreply at git.blender.org
Wed Mar 20 14:03:41 CET 2019


Commit: daa4d4dd25877c3352d26c6ac89a4cc2e05c10fa
Author: Jeroen Bakker
Date:   Fri Mar 15 12:10:09 2019 +0100
Branches: master
https://developer.blender.org/rBdaa4d4dd25877c3352d26c6ac89a4cc2e05c10fa

Fix T62248: Infinite Hotspot Size Crop Node

When the area of the crop node is zero the hotspot margin becomes infinite.
This makes the gizmo by default think the translate mode hotspot is everywhere.

This fix will return a state if the INFINITY is detected so we can
return the hotspot drawing.

The cage2d gizmo is still not usable for sizes of 0 by 0 as now it won't
draw anything. the issues of the gizmo should be re-designed so we can
mitigate these limitations. But that is out of scope for this fix.

Reviewed By: campbellbarton

Maniphest Tasks: T62248

Differential Revision: https://developer.blender.org/D4516

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

M	source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c

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

diff --git a/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c
index d25f982fc23..2d8f48f8187 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/cage2d_gizmo.c
@@ -60,7 +60,7 @@
 #define GIZMO_RESIZER_SIZE 10.0f
 #define GIZMO_MARGIN_OFFSET_SCALE 1.5f
 
-static void gizmo_calc_rect_view_scale(
+static bool gizmo_calc_rect_view_scale(
         const wmGizmo *gz, const float dims[2], float scale[2])
 {
 	float matrix_final_no_offset[4][4];
@@ -79,11 +79,19 @@ static void gizmo_calc_rect_view_scale(
 	mul_v2_v2(x_axis, asp);
 	mul_v2_v2(y_axis, asp);
 
-	scale[0] = 1.0f / len_v3(x_axis);
-	scale[1] = 1.0f / len_v3(y_axis);
+	float len_x_axis = len_v3(x_axis);
+	float len_y_axis = len_v3(y_axis);
+
+	if (len_x_axis == 0.0f || len_y_axis == 0.0f) {
+		return false;
+	}
+
+	scale[0] = 1.0f / len_x_axis;
+	scale[1] = 1.0f / len_y_axis;
+	return true;
 }
 
-static void gizmo_calc_rect_view_margin(
+static bool gizmo_calc_rect_view_margin(
         const wmGizmo *gz, const float dims[2], float margin[2])
 {
 	float handle_size;
@@ -95,9 +103,12 @@ static void gizmo_calc_rect_view_margin(
 	}
 	handle_size *= gz->scale_final;
 	float scale_xy[2];
-	gizmo_calc_rect_view_scale(gz, dims, scale_xy);
+	if (!gizmo_calc_rect_view_scale(gz, dims, scale_xy)) {
+		return false;
+	};
 	margin[0] = ((handle_size * scale_xy[0]));
 	margin[1] = ((handle_size * scale_xy[1]));
+	return true;
 }
 
 /* -------------------------------------------------------------------- */
@@ -725,7 +736,10 @@ static int gizmo_cage2d_test_select(
 	}
 
 	float margin[2];
-	gizmo_calc_rect_view_margin(gz, dims, margin);
+	if (!gizmo_calc_rect_view_margin(gz, dims, margin)) {
+		return -1;
+	}
+
 	/* expand for hotspot */
 	const float size[2] = {size_real[0] + margin[0] / 2, size_real[1] + margin[1] / 2};



More information about the Bf-blender-cvs mailing list