diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-02-13 19:14:29 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-02-13 19:14:29 +0400 |
commit | 4fe94b2ef67f5b1d8d535b8578038866a5f5d888 (patch) | |
tree | f35eace0ca6389ea49d64ab7ae2914b764c7ee4d /source/blender/editors | |
parent | fe855a83d7326568e413de36c79294a1843b2fa3 (diff) |
there were more places hook modifier type wasn't checked and could crash - add utility function which doest this.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/object/object_hook.c | 71 |
1 files changed, 34 insertions, 37 deletions
diff --git a/source/blender/editors/object/object_hook.c b/source/blender/editors/object/object_hook.c index 7060c69cb9e..1387ef94091 100644 --- a/source/blender/editors/object/object_hook.c +++ b/source/blender/editors/object/object_hook.c @@ -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; } |