RNA: check for duplicate manipulator names
authorCampbell Barton <ideasman42@gmail.com>
Wed, 23 Aug 2017 06:22:48 +0000 (16:22 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 23 Aug 2017 06:22:48 +0000 (16:22 +1000)
source/blender/makesrna/intern/rna_wm_manipulator.c

index a0fdd76e4a394ba8725c9b6c0d7594ed09cc5177..b074433e3b5f9a989c7ff7dcbbcc6ef901781b49 100644 (file)
@@ -434,14 +434,6 @@ static StructRNA *rna_Manipulator_register(
                return NULL;
        }
 
-       {   /* allocate the idname */
-               const uint idname_len = strlen(temp_buffers.idname) + 1;
-               char *ch = MEM_mallocN(
-                       sizeof(char) * idname_len, __func__);
-               dummywt.idname = ch;
-               memcpy(ch, temp_buffers.idname, idname_len);
-       }
-
        /* check if we have registered this manipulator type before, and remove it */
        {
                const wmManipulatorType *wt = WM_manipulatortype_find(dummywt.idname, true);
@@ -449,6 +441,17 @@ static StructRNA *rna_Manipulator_register(
                        rna_Manipulator_unregister(bmain, wt->ext.srna);
                }
        }
+       if (!RNA_struct_available_or_report(reports, identifier)) {
+               return NULL;
+       }
+
+       {   /* allocate the idname */
+               const uint idname_len = strlen(temp_buffers.idname) + 1;
+               char *ch = MEM_mallocN(
+                       sizeof(char) * idname_len, __func__);
+               dummywt.idname = ch;
+               memcpy(ch, temp_buffers.idname, idname_len);
+       }
 
        /* create a new manipulator type */
        dummywt.ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, dummywt.idname, &RNA_Manipulator);
@@ -739,6 +742,17 @@ static StructRNA *rna_ManipulatorGroup_register(
                return NULL;
        }
 
+       /* check if we have registered this manipulatorgroup type before, and remove it */
+       {
+               wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(dummywgt.idname, true);
+               if (wgt && wgt->ext.srna) {
+                       rna_ManipulatorGroup_unregister(bmain, wgt->ext.srna);
+               }
+       }
+       if (!RNA_struct_available_or_report(reports, identifier)) {
+               return NULL;
+       }
+
        {   /* allocate the idname */
                const uint idname_len = strlen(temp_buffers.idname) + 1;
                const uint name_len = strlen(temp_buffers.name) + 1;
@@ -751,14 +765,6 @@ static StructRNA *rna_ManipulatorGroup_register(
                dummywgt.name = ch;
        }
 
-       /* check if we have registered this manipulatorgroup type before, and remove it */
-       {
-               wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(dummywgt.idname, true);
-               if (wgt && wgt->ext.srna) {
-                       rna_ManipulatorGroup_unregister(bmain, wgt->ext.srna);
-               }
-       }
-
        /* create a new manipulatorgroup type */
        dummywgt.ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, dummywgt.idname, &RNA_ManipulatorGroup);
        RNA_def_struct_flag(dummywgt.ext.srna, STRUCT_NO_IDPROPERTIES); /* manipulatorgroup properties are registered separately */