[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54530] trunk/blender/source/blender/ editors/object/object_hook.c: there were more places hook modifier type wasn' t checked and could crash - add utility function which doest this.
Campbell Barton
ideasman42 at gmail.com
Wed Feb 13 16:14:29 CET 2013
Revision: 54530
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54530
Author: campbellbarton
Date: 2013-02-13 15:14:29 +0000 (Wed, 13 Feb 2013)
Log Message:
-----------
there were more places hook modifier type wasn't checked and could crash - add utility function which doest this.
Modified Paths:
--------------
trunk/blender/source/blender/editors/object/object_hook.c
Modified: trunk/blender/source/blender/editors/object/object_hook.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_hook.c 2013-02-13 15:03:36 UTC (rev 54529)
+++ trunk/blender/source/blender/editors/object/object_hook.c 2013-02-13 15:14:29 UTC (rev 54530)
@@ -386,6 +386,31 @@
}
}
+static void object_hook_from_context(bContext *C, PointerRNA *ptr,
+ 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 @@
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, &ob, &hmd);
+ if (hmd == NULL) {
BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
return OPERATOR_CANCELLED;
}
@@ -732,15 +750,8 @@
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, &ob, &hmd);
+ if (hmd == NULL) {
BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
return OPERATOR_CANCELLED;
}
@@ -790,15 +801,8 @@
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, &ob, &hmd);
+ if (hmd == NULL) {
BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
return OPERATOR_CANCELLED;
}
@@ -852,15 +856,8 @@
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, &ob, &hmd);
+ if (hmd == NULL) {
BKE_report(op->reports, RPT_ERROR, "Could not find hook modifier");
return OPERATOR_CANCELLED;
}
More information about the Bf-blender-cvs
mailing list