Fix infinite loop when reparenting bones in the bone editor. Also fixed issues with bones sometimes returning incorrect children.

This commit is contained in:
Relintai 2022-08-19 23:46:14 +02:00
parent 95767b2cea
commit a21352637e
2 changed files with 6 additions and 45 deletions

View File

@ -637,6 +637,8 @@ void SkeletonEditor::_update_properties() {
}
void SkeletonEditor::update_joint_tree() {
skeleton->force_update_all_bone_transforms();
joint_tree->clear();
if (!skeleton) {
@ -676,49 +678,6 @@ void SkeletonEditor::update_joint_tree() {
}
}
/*
void SkeletonEditor::update_joint_tree() {
skeleton->force_update_all_bone_transforms();
joint_tree->clear();
if (skeleton == nullptr)
return;
TreeItem *root = joint_tree->create_item();
Map<int, TreeItem *> items;
items.insert(-1, root);
Ref<Texture> bone_icon = get_theme_icon("Bone", "EditorIcons");
Vector<int> bones_to_process = skeleton->get_parentless_bones();
while (bones_to_process.size() > 0) {
int current_bone_idx = bones_to_process[0];
bones_to_process.erase(current_bone_idx);
const int parent_idx = skeleton->get_bone_parent(current_bone_idx);
TreeItem *parent_item = items.find(parent_idx)->get();
TreeItem *joint_item = joint_tree->create_item(parent_item);
items.insert(current_bone_idx, joint_item);
joint_item->set_text(0, skeleton->get_bone_name(current_bone_idx));
joint_item->set_icon(0, bone_icon);
joint_item->set_selectable(0, true);
joint_item->set_metadata(0, "bones/" + itos(current_bone_idx));
// Add the bone's children to the list of bones to be processed
Vector<int> current_bone_child_bones = skeleton->get_bone_children(current_bone_idx);
int child_bone_size = current_bone_child_bones.size();
for (int i = 0; i < child_bone_size; i++) {
bones_to_process.push_back(current_bone_child_bones[i]);
}
}
}
*/
void SkeletonEditor::update_editors() {
}

View File

@ -225,6 +225,10 @@ void Skeleton::_update_process_order() {
parentless_bones.clear();
for (int i = 0; i < len; i++) {
bonesptr[i].child_bones.clear();
}
for (int i = 0; i < len; i++) {
if (bonesptr[i].parent >= len) {
//validate this just in case
@ -232,8 +236,6 @@ void Skeleton::_update_process_order() {
bonesptr[i].parent = -1;
}
bonesptr[i].child_bones.clear();
if (bonesptr[i].parent != -1) {
int parent_bone_idx = bonesptr[i].parent;