Manipulator: allow py manipulators w/o properties
authorCampbell Barton <ideasman42@gmail.com>
Mon, 17 Jul 2017 02:29:37 +0000 (12:29 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 17 Jul 2017 02:29:37 +0000 (12:29 +1000)
These could be used for manipulators that run operators.

source/blender/python/intern/bpy_manipulator_wrap.c

index 7d02c2963d7b0a4ef5134b535a7681ba45ef0f37..db9fcdb377a052f34a29755920482261d13ac37f 100644 (file)
@@ -143,27 +143,32 @@ static void manipulator_properties_init(wmManipulatorType *wt)
                 * get direct from the dict to avoid raising a load of attribute errors (yes this isnt ideal) - campbell */
                PyObject *py_class_dict = py_class->tp_dict;
                PyObject *bl_target_properties = PyDict_GetItem(py_class_dict, bpy_intern_str_bl_target_properties);
-               PyObject *bl_target_properties_fast;
 
-               if (!(bl_target_properties_fast = PySequence_Fast(bl_target_properties, "bl_target_properties sequence"))) {
-                       /* PySequence_Fast sets the error */
-                       PyErr_Print();
-                       PyErr_Clear();
-                       return;
-               }
-
-               const uint items_len = PySequence_Fast_GET_SIZE(bl_target_properties_fast);
-               PyObject **items = PySequence_Fast_ITEMS(bl_target_properties_fast);
-
-               for (uint i = 0; i < items_len; i++) {
-                       if (!bpy_manipulatortype_target_property_def(wt, items[i])) {
+               /* Some widgets may only exist to activate operators. */
+               if (bl_target_properties != NULL) {
+                       PyObject *bl_target_properties_fast;
+                       if (!(bl_target_properties_fast = PySequence_Fast(
+                                 bl_target_properties, "bl_target_properties sequence")))
+                       {
+                               /* PySequence_Fast sets the error */
                                PyErr_Print();
                                PyErr_Clear();
-                               break;
+                               return;
                        }
-               }
 
-               Py_DECREF(bl_target_properties_fast);
+                       const uint items_len = PySequence_Fast_GET_SIZE(bl_target_properties_fast);
+                       PyObject **items = PySequence_Fast_ITEMS(bl_target_properties_fast);
+
+                       for (uint i = 0; i < items_len; i++) {
+                               if (!bpy_manipulatortype_target_property_def(wt, items[i])) {
+                                       PyErr_Print();
+                                       PyErr_Clear();
+                                       break;
+                               }
+                       }
+
+                       Py_DECREF(bl_target_properties_fast);
+               }
        }
 }