Fix: Segfault when inserting keyframes

`action_fcurve_ensure` can be passed a nullptr for
the PointerRNA, which the function didn't check for
after the refactor.
This commit is contained in:
Christoph Lendenfeld 2023-11-24 15:28:15 +01:00
parent 9c2330d821
commit a65cd72479
2 changed files with 11 additions and 8 deletions

View File

@ -17,6 +17,7 @@ namespace blender::animrig {
/**
* Get (or add relevant data to be able to do so) F-Curve from the given Action,
* for the given Animation Data block. This assumes that all the destinations are valid.
* \param ptr can be a null pointer.
*/
FCurve *action_fcurve_ensure(Main *bmain,
bAction *act,

View File

@ -60,19 +60,21 @@ FCurve *action_fcurve_ensure(Main *bmain,
fcu->rna_path = BLI_strdup(rna_path);
fcu->array_index = array_index;
if (U.autokey_flag & AUTOKEY_FLAG_XYZ2RGB) {
if (U.autokey_flag & AUTOKEY_FLAG_XYZ2RGB && ptr != nullptr) {
/* For Loc/Rot/Scale and also Color F-Curves, the color of the F-Curve in the Graph Editor,
* is determined by the array index for the F-Curve.
*/
PropertyRNA *prop;
PointerRNA r_ptr;
RNA_path_resolve_property(ptr, rna_path, &r_ptr, &prop);
PropertySubType prop_subtype = RNA_property_subtype(prop);
if (ELEM(prop_subtype, PROP_TRANSLATION, PROP_XYZ, PROP_EULER, PROP_COLOR, PROP_COORDS)) {
fcu->color_mode = FCURVE_COLOR_AUTO_RGB;
}
else if (ELEM(prop_subtype, PROP_QUATERNION)) {
fcu->color_mode = FCURVE_COLOR_AUTO_YRGB;
const bool resolved = RNA_path_resolve_property(ptr, rna_path, &r_ptr, &prop);
if (resolved) {
PropertySubType prop_subtype = RNA_property_subtype(prop);
if (ELEM(prop_subtype, PROP_TRANSLATION, PROP_XYZ, PROP_EULER, PROP_COLOR, PROP_COORDS)) {
fcu->color_mode = FCURVE_COLOR_AUTO_RGB;
}
else if (ELEM(prop_subtype, PROP_QUATERNION)) {
fcu->color_mode = FCURVE_COLOR_AUTO_YRGB;
}
}
}