Merge pull request #52955 from nekomatata/fix-kinematic-collision-reference-3.x

This commit is contained in:
Rémi Verschelde 2021-09-23 10:26:17 +02:00 committed by GitHub
commit 08887fd391
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View file

@ -981,7 +981,8 @@ Ref<KinematicCollision2D> KinematicBody2D::_move(const Vector2 &p_motion, bool p
Collision col; Collision col;
if (move_and_collide(p_motion, p_infinite_inertia, col, p_exclude_raycast_shapes, p_test_only)) { if (move_and_collide(p_motion, p_infinite_inertia, col, p_exclude_raycast_shapes, p_test_only)) {
if (motion_cache.is_null()) { // Create a new instance when the cached reference is invalid or still in use in script.
if (motion_cache.is_null() || motion_cache->reference_get_count() > 1) {
motion_cache.instance(); motion_cache.instance();
motion_cache->owner = this; motion_cache->owner = this;
} }
@ -1320,7 +1321,8 @@ Ref<KinematicCollision2D> KinematicBody2D::_get_slide_collision(int p_bounce) {
slide_colliders.resize(p_bounce + 1); slide_colliders.resize(p_bounce + 1);
} }
if (slide_colliders[p_bounce].is_null()) { // Create a new instance when the cached reference is invalid or still in use in script.
if (slide_colliders[p_bounce].is_null() || slide_colliders[p_bounce]->reference_get_count() > 1) {
slide_colliders.write[p_bounce].instance(); slide_colliders.write[p_bounce].instance();
slide_colliders.write[p_bounce]->owner = this; slide_colliders.write[p_bounce]->owner = this;
} }

View file

@ -960,7 +960,8 @@ void RigidBody::_reload_physics_characteristics() {
Ref<KinematicCollision> KinematicBody::_move(const Vector3 &p_motion, bool p_infinite_inertia, bool p_exclude_raycast_shapes, bool p_test_only) { Ref<KinematicCollision> KinematicBody::_move(const Vector3 &p_motion, bool p_infinite_inertia, bool p_exclude_raycast_shapes, bool p_test_only) {
Collision col; Collision col;
if (move_and_collide(p_motion, p_infinite_inertia, col, p_exclude_raycast_shapes, p_test_only)) { if (move_and_collide(p_motion, p_infinite_inertia, col, p_exclude_raycast_shapes, p_test_only)) {
if (motion_cache.is_null()) { // Create a new instance when the cached reference is invalid or still in use in script.
if (motion_cache.is_null() || motion_cache->reference_get_count() > 1) {
motion_cache.instance(); motion_cache.instance();
motion_cache->owner = this; motion_cache->owner = this;
} }
@ -1330,7 +1331,8 @@ Ref<KinematicCollision> KinematicBody::_get_slide_collision(int p_bounce) {
slide_colliders.resize(p_bounce + 1); slide_colliders.resize(p_bounce + 1);
} }
if (slide_colliders[p_bounce].is_null()) { // Create a new instance when the cached reference is invalid or still in use in script.
if (slide_colliders[p_bounce].is_null() || slide_colliders[p_bounce]->reference_get_count() > 1) {
slide_colliders.write[p_bounce].instance(); slide_colliders.write[p_bounce].instance();
slide_colliders.write[p_bounce]->owner = this; slide_colliders.write[p_bounce]->owner = this;
} }