Hi @CJtheTiger, sorry for the delay took me some time to properly understand everything.
First of all with the next release it does not crash anymore.
With 2023.1 it still does and the only way would be to either as you did remove the weight tag or call AddUndo(UNDOTYPE_DELETEOBJ) before you remove a bone. With that said taking in consideration your setup creating an undo is not something you would want (at least I think).
Internally the weight tags, cache the joint list and re-use it so that's why it was crashing (due to a missing nullptr check). But with the next version this is properly handled so it does not crash anymore. Still to properly notify the weight tag that a bones needs to be removed you need to add an undo UNDOTYPE_DELETEOBJ
. So the best option would be to to manually delete your bones from all weight tags with something like:
typedef Bool(*IterationCallback)(BaseObject* op);
void RecurseHierarchy(BaseObject* op, IterationCallback callback)
{
while (op)
{
if (callback(op))
RecurseHierarchy(op->GetDown(), callback);
op = op->GetNext();
}
}
void AdvancedIkSpline::clear(BaseObject* op)
{
BaseObject* directChild = op->GetDown();
while (directChild)
{
RecurseHierarchy(directChild, [](BaseObject* child) {
CAWeightTag* weightTag = nullptr;
Int32 dummy;
if (child->GetType() != Ojoint)
return true;
weightTag = static_cast<CAJointObject*>(child)->GetWeightTag(dummy);
// Remove from all Weight Tags
while (weightTag)
{
weightTag->RemoveJoint(child);
weightTag = static_cast<CAJointObject*>(child)->GetWeightTag(dummy);
}
return true;
});
directChild->Remove();
directChild = op->GetDown();
}
}
In any case I would say the workflow is a bit wanky, and you have to understand Cinema 4D was never designed to support that an object create/delete objects in the scene.
Cheers,
Maxime.