[Bf-blender-cvs] [cc6ca138527] master: Fix T90634: Gizmo.target_set_value() crash without a valid property

Campbell Barton noreply at git.blender.org
Mon Oct 11 11:20:35 CEST 2021


Commit: cc6ca1385279f4bd8817c8f23db40b3b43fa402b
Author: Campbell Barton
Date:   Mon Oct 11 20:06:09 2021 +1100
Branches: master
https://developer.blender.org/rBcc6ca1385279f4bd8817c8f23db40b3b43fa402b

Fix T90634: Gizmo.target_set_value() crash without a valid property

Raise an exception when target properties have not been set.

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

M	source/blender/python/intern/bpy_rna_gizmo.c

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

diff --git a/source/blender/python/intern/bpy_rna_gizmo.c b/source/blender/python/intern/bpy_rna_gizmo.c
index 5294f56d5c6..adae68bd7b4 100644
--- a/source/blender/python/intern/bpy_rna_gizmo.c
+++ b/source/blender/python/intern/bpy_rna_gizmo.c
@@ -94,6 +94,26 @@ static int py_rna_gizmo_target_id_parse(PyObject *o, void *p)
   return 1;
 }
 
+static int py_rna_gizmo_target_id_parse_and_ensure_is_valid(PyObject *o, void *p)
+{
+  if (py_rna_gizmo_target_id_parse(o, p) == 0) {
+    return 0;
+  }
+  struct BPyGizmoWithTarget *gizmo_with_target = p;
+  wmGizmo *gz = gizmo_with_target->gz;
+  wmGizmoProperty *gz_prop = gizmo_with_target->gz_prop;
+  if (!WM_gizmo_target_property_is_valid(gz_prop)) {
+    const char *gz_prop_id = PyUnicode_AsUTF8(o);
+    PyErr_Format(PyExc_ValueError,
+                 "Gizmo target property '%s.%s' has not been initialized, "
+                 "Call \"target_set_prop\" first!",
+                 gz->type->idname,
+                 gz_prop_id);
+    return 0;
+  }
+  return 1;
+}
+
 static int py_rna_gizmo_target_type_id_parse(PyObject *o, void *p)
 {
   struct BPyGizmoWithTargetType *gizmo_with_target = p;
@@ -424,7 +444,7 @@ static PyObject *bpy_gizmo_target_get_value(PyObject *UNUSED(self), PyObject *ar
                                         py_rna_gizmo_parse,
                                         &params.gz_with_target.gz,
                                         /* `target` */
-                                        py_rna_gizmo_target_id_parse,
+                                        py_rna_gizmo_target_id_parse_and_ensure_is_valid,
                                         &params.gz_with_target)) {
     goto fail;
   }
@@ -482,7 +502,7 @@ static PyObject *bpy_gizmo_target_set_value(PyObject *UNUSED(self), PyObject *ar
                                         py_rna_gizmo_parse,
                                         &params.gz_with_target.gz,
                                         /* `target` */
-                                        py_rna_gizmo_target_id_parse,
+                                        py_rna_gizmo_target_id_parse_and_ensure_is_valid,
                                         &params.gz_with_target,
                                         /* `value` */
                                         &params.value)) {
@@ -551,7 +571,7 @@ static PyObject *bpy_gizmo_target_get_range(PyObject *UNUSED(self), PyObject *ar
                                         py_rna_gizmo_parse,
                                         &params.gz_with_target.gz,
                                         /* `target` */
-                                        py_rna_gizmo_target_id_parse,
+                                        py_rna_gizmo_target_id_parse_and_ensure_is_valid,
                                         &params.gz_with_target)) {
     goto fail;
   }



More information about the Bf-blender-cvs mailing list