1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Fix console errors and crash in cleanup code for PhysicalBoneSimulator3D

This commit is contained in:
Mike Estee
2025-03-02 13:40:27 -08:00
committed by Rémi Verschelde
parent 827f9d95f2
commit d39003c0bf
3 changed files with 23 additions and 5 deletions

View File

@@ -73,10 +73,15 @@ void PhysicalBoneSimulator3D::_pose_updated() {
if (!skeleton || simulating) { if (!skeleton || simulating) {
return; return;
} }
ERR_FAIL_COND(skeleton->get_bone_count() != bones.size()); // If this triggers that means that we likely haven't rebuilt the bone list yet.
if (skeleton->get_bone_count() != bones.size()) {
// NOTE: this is re-entrant and will call _pose_updated again.
_bone_list_changed();
} else {
for (int i = 0; i < skeleton->get_bone_count(); i++) { for (int i = 0; i < skeleton->get_bone_count(); i++) {
_bone_pose_updated(skeleton, i); _bone_pose_updated(skeleton, i);
} }
}
} }
void PhysicalBoneSimulator3D::_bone_pose_updated(Skeleton3D *p_skeleton, int p_bone_id) { void PhysicalBoneSimulator3D::_bone_pose_updated(Skeleton3D *p_skeleton, int p_bone_id) {

View File

@@ -752,8 +752,9 @@ void PhysicalBone3D::_get_property_list(List<PropertyInfo> *p_list) const {
void PhysicalBone3D::_notification(int p_what) { void PhysicalBone3D::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_ENTER_TREE: // We need to wait until the bone has finished being added to the tree
case NOTIFICATION_PARENTED: // or none of the global transform calls will work correctly.
case NOTIFICATION_POST_ENTER_TREE:
_update_simulator_path(); _update_simulator_path();
update_bone_id(); update_bone_id();
reset_to_rest_position(); reset_to_rest_position();
@@ -763,6 +764,9 @@ void PhysicalBone3D::_notification(int p_what) {
} }
break; break;
// If we're detached from the skeleton we need to
// clear our references to it.
case NOTIFICATION_UNPARENTED:
case NOTIFICATION_EXIT_TREE: { case NOTIFICATION_EXIT_TREE: {
PhysicalBoneSimulator3D *simulator = get_simulator(); PhysicalBoneSimulator3D *simulator = get_simulator();
if (simulator) { if (simulator) {

View File

@@ -838,6 +838,13 @@ bool Skeleton3D::is_show_rest_only() const {
void Skeleton3D::clear_bones() { void Skeleton3D::clear_bones() {
bones.clear(); bones.clear();
name_to_bone_index.clear(); name_to_bone_index.clear();
// All these structures contain references to now invalid bone indices.
skin_bindings.clear();
bone_global_pose_dirty.clear();
parentless_bones.clear();
nested_set_offset_to_bone_index.clear();
process_order_dirty = true; process_order_dirty = true;
version++; version++;
_make_dirty(); _make_dirty();
@@ -1091,6 +1098,8 @@ void Skeleton3D::_force_update_bone_children_transforms(int p_bone_idx) const {
const int bone_size = bones.size(); const int bone_size = bones.size();
ERR_FAIL_INDEX(p_bone_idx, bone_size); ERR_FAIL_INDEX(p_bone_idx, bone_size);
_update_process_order();
Bone *bonesptr = bones.ptr(); Bone *bonesptr = bones.ptr();
// Loop through nested set. // Loop through nested set.