Fix T84367: Fix crash when showing invalid/legacy constraints

Exposed by rBeaa44afe703e.

Definition for CONSTRAINT_TYPE_NULL is not totally clear (it is set for
constraints without data, see an old comment from Ton), but for these, a
TypeInfo cannot be fetched.

Avoid processing those constraints in UI code, just do nothing instead.

Maniphest Tasks: T84367

Differential Revision: https://developer.blender.org/D9987
This commit is contained in:
Philipp Oeser 2021-01-04 14:14:13 +01:00
parent 1f41bdc6f3
commit 36ae6e66c1
Notes: blender-bot 2023-02-14 08:47:25 +01:00
Referenced by issue #84367, Select bone (with constraint) in Pose Mode from Outliner (and constraint tab in Properties Editor showing) crashes
1 changed files with 18 additions and 0 deletions

View File

@ -2301,6 +2301,11 @@ static void object_constraint_panel_id(void *md_link, char *r_name)
bConstraint *con = (bConstraint *)md_link;
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_from_type(con->type);
/* Cannot get TypeInfo for invalid/legacy constraints. */
if (cti == NULL) {
return;
}
strcpy(r_name, CONSTRAINT_TYPE_PANEL_PREFIX);
strcat(r_name, cti->structName);
}
@ -2310,6 +2315,11 @@ static void bone_constraint_panel_id(void *md_link, char *r_name)
bConstraint *con = (bConstraint *)md_link;
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_from_type(con->type);
/* Cannot get TypeInfo for invalid/legacy constraints. */
if (cti == NULL) {
return;
}
strcpy(r_name, CONSTRAINT_BONE_TYPE_PANEL_PREFIX);
strcat(r_name, cti->structName);
}
@ -2340,6 +2350,10 @@ void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C, bool use_bone_
UI_panels_free_instanced(C, region);
bConstraint *con = (constraints == NULL) ? NULL : constraints->first;
for (int i = 0; con; i++, con = con->next) {
/* Dont show invalid/legacy constraints. */
if (con->type == CONSTRAINT_TYPE_NULL) {
continue;
}
/* Dont show temporary constraints (AutoIK and targetless IK constraints). */
if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
bKinematicConstraint *data = con->data;
@ -2369,6 +2383,10 @@ void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C, bool use_bone_
/* Assuming there's only one group of instanced panels, update the custom data pointers. */
Panel *panel = region->panels.first;
LISTBASE_FOREACH (bConstraint *, con, constraints) {
/* Dont show invalid/legacy constraints. */
if (con->type == CONSTRAINT_TYPE_NULL) {
continue;
}
/* Dont show temporary constraints (AutoIK and targetless IK constraints). */
if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
bKinematicConstraint *data = con->data;