diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-10-11 12:06:09 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-10-11 12:19:19 +0300 |
commit | cc6ca1385279f4bd8817c8f23db40b3b43fa402b (patch) | |
tree | 5562e6396b8843182cdf8b67ae40960a624b51c6 /source | |
parent | a6d34f4c3f2a86af1cabf75c89e85a35d38073c3 (diff) |
Fix T90634: Gizmo.target_set_value() crash without a valid property
Raise an exception when target properties have not been set.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/intern/bpy_rna_gizmo.c | 26 |
1 files changed, 23 insertions, 3 deletions
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, ¶ms.gz_with_target.gz, /* `target` */ - py_rna_gizmo_target_id_parse, + py_rna_gizmo_target_id_parse_and_ensure_is_valid, ¶ms.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, ¶ms.gz_with_target.gz, /* `target` */ - py_rna_gizmo_target_id_parse, + py_rna_gizmo_target_id_parse_and_ensure_is_valid, ¶ms.gz_with_target, /* `value` */ ¶ms.value)) { @@ -551,7 +571,7 @@ static PyObject *bpy_gizmo_target_get_range(PyObject *UNUSED(self), PyObject *ar py_rna_gizmo_parse, ¶ms.gz_with_target.gz, /* `target` */ - py_rna_gizmo_target_id_parse, + py_rna_gizmo_target_id_parse_and_ensure_is_valid, ¶ms.gz_with_target)) { goto fail; } |