Anim: fix assertion when un-assigning bone collection parent

When using `bone_collection.parent = None` in Python, debug builds would
hit an assertion. This is now fixed.
This commit is contained in:
Sybren A. Stüvel
2024-01-11 14:32:31 +01:00
parent 649eec7774
commit 15c7c77967
2 changed files with 11 additions and 5 deletions

View File

@@ -1157,6 +1157,9 @@ bool armature_bonecoll_is_descendant_of(const bArmature *armature,
const int potential_parent_index,
const int potential_descendant_index)
{
BLI_assert_msg(potential_descendant_index >= 0,
"Potential descendant has to exist for this function call to make sense.");
if (armature_bonecoll_is_child_of(armature, potential_parent_index, potential_descendant_index))
{
/* Found a direct child. */

View File

@@ -281,11 +281,14 @@ static void rna_BoneCollection_parent_set(PointerRNA *ptr,
const int from_parent_index = armature_bonecoll_find_parent_index(armature, from_bcoll_index);
const int to_parent_index = armature_bonecoll_find_index(armature, to_parent);
if (to_parent_index == from_bcoll_index ||
armature_bonecoll_is_descendant_of(armature, from_bcoll_index, to_parent_index))
{
BKE_report(reports, RPT_ERROR, "Cannot make a bone collection a descendant of itself");
return;
if (to_parent_index >= 0) {
/* No need to check for parenthood cycles when the bone collection is turned into a root. */
if (to_parent_index == from_bcoll_index ||
armature_bonecoll_is_descendant_of(armature, from_bcoll_index, to_parent_index))
{
BKE_report(reports, RPT_ERROR, "Cannot make a bone collection a descendant of itself");
return;
}
}
armature_bonecoll_move_to_parent(