[Bf-blender-cvs] [81022000063] master: Cleanup/sanitize usages of G.debug_value.

Bastien Montagne noreply at git.blender.org
Wed Jan 16 19:44:09 CET 2019


Commit: 81022000063c1fe84d85e8de416d8ab0c2c4c516
Author: Bastien Montagne
Date:   Wed Jan 16 19:41:29 2019 +0100
Branches: master
https://developer.blender.org/rB81022000063c1fe84d85e8de416d8ab0c2c4c516

Cleanup/sanitize usages of G.debug_value.

There was no documentation at all, some very bad practices (like using
G.debug_value > 0 as some sort of global debug print switch), and even
an overlapping use of '1' value...

Also, python setter did not check for valid range (since this is a
short, not an int).

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

M	source/blender/blenkernel/BKE_global.h
M	source/blender/blenkernel/intern/cloth.c
M	source/blender/editors/screen/area.c
M	source/blender/modifiers/intern/MOD_cloth.c
M	source/blender/modifiers/intern/MOD_collision.c
M	source/blender/python/intern/bpy_app.c

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

diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h
index b2991679775..97e23a952db 100644
--- a/source/blender/blenkernel/BKE_global.h
+++ b/source/blender/blenkernel/BKE_global.h
@@ -73,7 +73,21 @@ typedef struct Global {
 	/* to indicate render is busy, prevent renderwindow events etc */
 	bool is_rendering;
 
-	/* debug value, can be set from the UI and python, used for testing nonstandard features */
+	/* Debug value, can be set from the UI and python, used for testing nonstandard features.
+	 * DO NOT abuse it with generic checks like `if (G.debug_value > 0)`. Do not use it as bitflags.
+	 * Only precise specific values should be checked for, to avoid unpredictable side-effects.
+	 * Please document here the value(s) you are using (or a range of values reserved to some area).
+	 *   * -16384 and below: Reserved for python (add-ons) usage.
+	 *   *     -1: Disable faster motion paths computation (since 08/2018).
+	 *   * 1 - 30: EEVEE debug/stats values (01/2018).
+	 *   *    101: Enable UI debug drawing of fullscreen area's corner widget (10/2014).
+	 *   *    527: Old mysterious switch in behavior of MeshDeform modifier (before 04/2010).
+	 *   *    777: Enable UI node panel's sockets polling (11/2011).
+	 *   *    799: Enable some mysterious new depsgraph behavior (05/2015).
+	 *   *   1112: Disable new Cloth internal springs hanlding (09/2014).
+	 *   *   1234: Disable new dyntopo code fixing skinny faces generation (04/2015).
+	 *   * 16384 and above: Reserved for python (add-ons) usage.
+	 */
 	short debug_value;
 
 	/* saved to the blend file as FileGlobal.globalf,
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 30b5d92bdb7..47afef444cf 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -515,8 +515,9 @@ void cloth_free_modifier(ClothModifierData *clmd )
 void cloth_free_modifier_extern(ClothModifierData *clmd )
 {
 	Cloth	*cloth = NULL;
-	if (G.debug_value > 0)
+	if (G.debug & G_DEBUG_SIMDATA) {
 		printf("cloth_free_modifier_extern\n");
+	}
 
 	if ( !clmd )
 		return;
@@ -524,8 +525,9 @@ void cloth_free_modifier_extern(ClothModifierData *clmd )
 	cloth = clmd->clothObject;
 
 	if ( cloth ) {
-		if (G.debug_value > 0)
+		if (G.debug & G_DEBUG_SIMDATA) {
 			printf("cloth_free_modifier_extern in\n");
+		}
 
 		BPH_cloth_solver_free(clmd);
 
@@ -728,8 +730,9 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, Mesh *mesh, fl
 	// If we have a clothObject, free it.
 	if ( clmd->clothObject != NULL ) {
 		cloth_free_modifier ( clmd );
-		if (G.debug_value > 0)
+		if (G.debug & G_DEBUG_SIMDATA) {
 			printf("cloth_free_modifier cloth_from_object\n");
+		}
 	}
 
 	// Allocate a new cloth object.
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 34a20c8ccf7..76c907a964a 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -210,7 +210,7 @@ static void area_draw_azone_fullscreen(short x1, short y1, short x2, short y2, f
 	 * The click_rect is the same as defined in fullscreen_click_rcti_init
 	 * Keep them both in sync */
 
-	if (G.debug_value == 1) {
+	if (G.debug_value == 101) {
 		rcti click_rect;
 		float icon_size = UI_DPI_ICON_SIZE + 7 * UI_DPI_FAC;
 
diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c
index 636c465d304..0c7c701e5e5 100644
--- a/source/blender/modifiers/intern/MOD_cloth.c
+++ b/source/blender/modifiers/intern/MOD_cloth.c
@@ -201,8 +201,9 @@ static void freeData(ModifierData *md)
 	ClothModifierData *clmd = (ClothModifierData *) md;
 
 	if (clmd) {
-		if (G.debug_value > 0)
+		if (G.debug & G_DEBUG_SIMDATA) {
 			printf("clothModifier_freeData\n");
+		}
 
 		cloth_free_modifier_extern(clmd);
 
diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c
index 011635e3012..7f4a0b91dbf 100644
--- a/source/blender/modifiers/intern/MOD_collision.c
+++ b/source/blender/modifiers/intern/MOD_collision.c
@@ -141,8 +141,9 @@ static void deformVerts(
 
 		current_time = DEG_get_ctime(ctx->depsgraph);
 
-		if (G.debug_value > 0)
+		if (G.debug & G_DEBUG_SIMDATA) {
 			printf("current_time %f, collmd->time_xnew %f\n", current_time, collmd->time_xnew);
+		}
 
 		mvert_num = mesh_src->totvert;
 
diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c
index bba9eee0316..01c8573f589 100644
--- a/source/blender/python/intern/bpy_app.c
+++ b/source/blender/python/intern/bpy_app.c
@@ -297,7 +297,7 @@ static PyObject *bpy_app_binary_path_python_get(PyObject *self, void *UNUSED(clo
 }
 
 PyDoc_STRVAR(bpy_app_debug_value_doc,
-"Int, number which can be set to non-zero values for testing purposes"
+"Short, number which can be set to non-zero values for testing purposes"
 );
 static PyObject *bpy_app_debug_value_get(PyObject *UNUSED(self), void *UNUSED(closure))
 {
@@ -313,7 +313,13 @@ static int bpy_app_debug_value_set(PyObject *UNUSED(self), PyObject *value, void
 		return -1;
 	}
 
-	G.debug_value = param;
+	if (param < SHRT_MIN || param > SHRT_MAX) {
+		PyErr_SetString(PyExc_ValueError,
+		                "bpy.app.debug_value can only be set to short range [-32768, 32767]");
+		return -1;
+	}
+
+	G.debug_value = (short)param;
 
 	WM_main_add_notifier(NC_WINDOW, NULL);



More information about the Bf-blender-cvs mailing list