Fix infinite recursion issues in Skeleton.

This commit is contained in:
Relintai 2022-08-11 22:32:25 +02:00
parent 575b830f68
commit 502f8f85c5
2 changed files with 15 additions and 4 deletions

View File

@ -218,6 +218,8 @@ void Skeleton::_update_process_order() {
return;
}
++updating;
Bone *bonesptr = bones.ptrw();
int len = bones.size();
@ -249,12 +251,15 @@ void Skeleton::_update_process_order() {
process_order_dirty = false;
--updating;
emit_signal("bones_updated");
}
void Skeleton::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_UPDATE_SKELETON: {
++updating;
// Update bone transforms
force_update_all_bone_transforms();
@ -321,6 +326,8 @@ void Skeleton::_notification(int p_what) {
}
}
--updating;
//TODO Not sure if this is useful or not in runtime
//#ifdef TOOLS_ENABLED
emit_signal("pose_updated");
@ -400,7 +407,7 @@ Transform Skeleton::get_bone_global_pose(int p_bone) const {
const int bone_size = bones.size();
ERR_FAIL_INDEX_V(p_bone, bone_size, Transform());
if (dirty) {
if (dirty && updating == 0) {
const_cast<Skeleton *>(this)->notification(NOTIFICATION_UPDATE_SKELETON);
}
@ -411,7 +418,7 @@ Transform Skeleton::get_bone_global_pose_no_override(int p_bone) const {
const int bone_size = bones.size();
ERR_FAIL_INDEX_V(p_bone, bone_size, Transform());
if (dirty) {
if (dirty && updating == 0) {
const_cast<Skeleton *>(this)->notification(NOTIFICATION_UPDATE_SKELETON);
}
@ -682,7 +689,7 @@ Transform Skeleton::get_bone_global_rest(int p_bone) const {
const int bone_size = bones.size();
ERR_FAIL_INDEX_V(p_bone, bone_size, Transform());
if (rest_dirty) {
if (rest_dirty && updating == 0) {
const_cast<Skeleton *>(this)->notification(NOTIFICATION_UPDATE_SKELETON);
}
@ -1069,17 +1076,19 @@ Ref<SkinReference> Skeleton::register_skin(const Ref<Skin> &p_skin) {
}
void Skeleton::force_update_all_dirty_bones() {
if (dirty) {
if (dirty && updating == 0) {
const_cast<Skeleton *>(this)->notification(NOTIFICATION_UPDATE_SKELETON);
}
}
void Skeleton::force_update_all_bone_transforms() {
++updating;
_update_process_order();
for (int i = 0; i < parentless_bones.size(); i++) {
force_update_bone_children_transforms(parentless_bones[i]);
}
--updating;
}
void Skeleton::force_update_bone_children_transforms(int p_bone_idx) {
@ -1357,6 +1366,7 @@ Skeleton::Skeleton() {
process_order_dirty = true;
show_rest_only = false;
rest_dirty = false;
updating = 0;
}
Skeleton::~Skeleton() {

View File

@ -151,6 +151,7 @@ private:
void _make_dirty();
bool dirty;
bool rest_dirty;
int updating;
bool show_rest_only;