diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-05-20 14:05:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-20 14:05:29 +0200 |
commit | db4cf6348266b515cdaf3d951b1bd403e5230c37 (patch) | |
tree | 0d69f152e7e3d201ed896890b8681a1cca19e77b | |
parent | f46a4841e7fffffdc8512155fcba8a03f50f7571 (diff) | |
parent | b19544e91d054c13597e3820dd05311e1852b30c (diff) |
Merge pull request #48860 from JohnM666/fix-basis-variant-initialization
Fix RigidBody3D.get_inverse_inertia_tensor() crash
-rw-r--r-- | core/variant/variant_internal.h | 17 | ||||
-rw-r--r-- | doc/classes/RigidBody3D.xml | 2 | ||||
-rw-r--r-- | scene/3d/physics_body_3d.cpp | 2 | ||||
-rw-r--r-- | scene/3d/physics_body_3d.h | 2 |
4 files changed, 15 insertions, 8 deletions
diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h index 7d33d85cd6..fb791f8c0c 100644 --- a/core/variant/variant_internal.h +++ b/core/variant/variant_internal.h @@ -43,18 +43,21 @@ public: v->type = p_type; switch (p_type) { - case Variant::AABB: - init_aabb(v); + case Variant::STRING: + init_string(v); break; case Variant::TRANSFORM2D: init_transform2d(v); break; + case Variant::AABB: + init_aabb(v); + break; + case Variant::BASIS: + init_basis(v); + break; case Variant::TRANSFORM: init_transform(v); break; - case Variant::STRING: - init_string(v); - break; case Variant::STRING_NAME: init_string_name(v); break; @@ -192,6 +195,10 @@ public: v->type = GetTypeInfo<T>::VARIANT_TYPE; } + // Should be in the same order as Variant::Type for consistency. + // Those primitive and vector types don't need an `init_` method: + // Nil, bool, float, Vector2/i, Rect2/i, Vector3/i, Plane, Quat, Color, RID. + // Object is a special case, handled via `object_assign_null`. _FORCE_INLINE_ static void init_string(Variant *v) { memnew_placement(v->_data._mem, String); v->type = Variant::STRING; diff --git a/doc/classes/RigidBody3D.xml b/doc/classes/RigidBody3D.xml index 2920c27a7a..2ee8e2697c 100644 --- a/doc/classes/RigidBody3D.xml +++ b/doc/classes/RigidBody3D.xml @@ -103,7 +103,7 @@ [b]Note:[/b] The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead. </description> </method> - <method name="get_inverse_inertia_tensor"> + <method name="get_inverse_inertia_tensor" qualifiers="const"> <return type="Basis"> </return> <description> diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index 93851aaedd..e895d18604 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -517,7 +517,7 @@ Vector3 RigidBody3D::get_angular_velocity() const { return angular_velocity; } -Basis RigidBody3D::get_inverse_inertia_tensor() { +Basis RigidBody3D::get_inverse_inertia_tensor() const { return inverse_inertia_tensor; } diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h index cf18b8ca82..818ff97730 100644 --- a/scene/3d/physics_body_3d.h +++ b/scene/3d/physics_body_3d.h @@ -183,7 +183,7 @@ public: void set_angular_velocity(const Vector3 &p_velocity); Vector3 get_angular_velocity() const override; - Basis get_inverse_inertia_tensor(); + Basis get_inverse_inertia_tensor() const; void set_gravity_scale(real_t p_gravity_scale); real_t get_gravity_scale() const; |