there were more places hook modifier type wasn't checked and could crash - add utilit...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 13 Feb 2013 15:14:29 +0000 (15:14 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 13 Feb 2013 15:14:29 +0000 (15:14 +0000)
source/blender/editors/object/object_hook.c

index 7060c69cb9e09213c0d60a3593927026559563b0..1387ef940911f44fed32e5d1e36ff98a2823845f 100644 (file)
@@ -386,6 +386,31 @@ static void select_editcurve_hook(Object *obedit, HookModifierData *hmd)
        }
 }
 
+static void object_hook_from_context(bContext *C, PointerRNA *ptr, const int num,
+                                     Object **r_ob, HookModifierData **r_hmd)
+{
+       Object *ob;
+       HookModifierData *hmd;
+
+       if (ptr->data) {  /* if modifier context is available, use that */
+               ob = ptr->id.data;
+               hmd = ptr->data;
+       }
+       else {  /* use the provided property */
+               ob = CTX_data_edit_object(C);
+               hmd = (HookModifierData *)BLI_findlink(&ob->modifiers, num);
+       }
+
+       if (ob && hmd && (hmd->modifier.type == eModifierType_Hook)) {
+               *r_ob = ob;
+               *r_hmd = hmd;
+       }
+       else {
+               *r_ob = NULL;
+               *r_hmd = NULL;
+       }
+}
+
 static void object_hook_select(Object *ob, HookModifierData *hmd) 
 {
        if (hmd->indexar == NULL)
@@ -663,16 +688,9 @@ static int object_hook_reset_exec(bContext *C, wmOperator *op)
        int num = RNA_enum_get(op->ptr, "modifier");
        Object *ob = NULL;
        HookModifierData *hmd = NULL;
-       
-       if (ptr.data) {     /* if modifier context is available, use that */
-               ob = ptr.id.data;
-               hmd = ptr.data;
-       }
-       else {          /* use the provided property */
-               ob = CTX_data_edit_object(C);
-               hmd = (HookModifierData *)BLI_findlink(&ob->modifiers, num);
-       }
-       if (!ob || !hmd) {
+
+       object_hook_from_context(C, &ptr, num, &ob, &hmd);
+       if (hmd == NULL) {
                BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
                return OPERATOR_CANCELLED;
        }
@@ -732,15 +750,8 @@ static int object_hook_recenter_exec(bContext *C, wmOperator *op)
        Scene *scene = CTX_data_scene(C);
        float bmat[3][3], imat[3][3];
        
-       if (ptr.data) {  /* if modifier context is available, use that */
-               ob = ptr.id.data;
-               hmd = ptr.data;
-       }
-       else {  /* use the provided property */
-               ob = CTX_data_edit_object(C);
-               hmd = (HookModifierData *)BLI_findlink(&ob->modifiers, num);
-       }
-       if (!ob || !hmd) {
+       object_hook_from_context(C, &ptr, num, &ob, &hmd);
+       if (hmd == NULL) {
                BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
                return OPERATOR_CANCELLED;
        }
@@ -790,15 +801,8 @@ static int object_hook_assign_exec(bContext *C, wmOperator *op)
        char name[MAX_NAME];
        int *indexar, tot;
        
-       if (ptr.data) {     /* if modifier context is available, use that */
-               ob = ptr.id.data;
-               hmd = ptr.data;
-       }
-       else {          /* use the provided property */
-               ob = CTX_data_edit_object(C);
-               hmd = (HookModifierData *)BLI_findlink(&ob->modifiers, num);
-       }
-       if (!ob || !hmd || (hmd->modifier.type != eModifierType_Hook)) {
+       object_hook_from_context(C, &ptr, num, &ob, &hmd);
+       if (hmd == NULL) {
                BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
                return OPERATOR_CANCELLED;
        }
@@ -852,15 +856,8 @@ static int object_hook_select_exec(bContext *C, wmOperator *op)
        Object *ob = NULL;
        HookModifierData *hmd = NULL;
        
-       if (ptr.data) {     /* if modifier context is available, use that */
-               ob = ptr.id.data;
-               hmd = ptr.data;
-       }
-       else {          /* use the provided property */
-               ob = CTX_data_edit_object(C);
-               hmd = (HookModifierData *)BLI_findlink(&ob->modifiers, num);
-       }
-       if (!ob || !hmd) {
+       object_hook_from_context(C, &ptr, num, &ob, &hmd);
+       if (hmd == NULL) {
                BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
                return OPERATOR_CANCELLED;
        }