Fix T96032: add null check to constraint operators

The constraint operators for delete, apply, copy and copy to selected
were missing null checks and could crash blender when called wrongly
from the python api.

Differential Revision: http://developer.blender.org/D14195
This commit is contained in:
Henrik Dick 2022-02-28 18:26:58 +01:00
parent 245722866d
commit 8c932ab43c
Notes: blender-bot 2023-02-14 00:10:08 +01:00
Referenced by issue #96032, Wrongly applying constraint make crashing Blender
1 changed files with 20 additions and 0 deletions

View File

@ -1443,6 +1443,11 @@ static int constraint_delete_exec(bContext *C, wmOperator *op)
Main *bmain = CTX_data_main(C);
Object *ob = ED_object_active_context(C);
bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
if (con == NULL) {
return OPERATOR_CANCELLED;
}
ListBase *lb = ED_object_constraint_list_from_constraint(ob, con, NULL);
/* Store name temporarily for report. */
@ -1510,6 +1515,11 @@ static int constraint_apply_exec(bContext *C, wmOperator *op)
Main *bmain = CTX_data_main(C);
Object *ob = ED_object_active_context(C);
bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
if (con == NULL) {
return OPERATOR_CANCELLED;
}
bPoseChannel *pchan;
ListBase *constraints = ED_object_constraint_list_from_constraint(ob, con, &pchan);
@ -1602,6 +1612,11 @@ static int constraint_copy_exec(bContext *C, wmOperator *op)
Main *bmain = CTX_data_main(C);
Object *ob = ED_object_active_context(C);
bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
if (con == NULL) {
return OPERATOR_CANCELLED;
}
bPoseChannel *pchan;
ListBase *constraints = ED_object_constraint_list_from_constraint(ob, con, &pchan);
@ -1682,6 +1697,11 @@ static int constraint_copy_to_selected_exec(bContext *C, wmOperator *op)
Main *bmain = CTX_data_main(C);
Object *obact = ED_object_active_context(C);
bConstraint *con = edit_constraint_property_get(C, op, obact, 0);
if (con == NULL) {
return OPERATOR_CANCELLED;
}
bPoseChannel *pchan;
ED_object_constraint_list_from_constraint(obact, con, &pchan);