Merge pull request #58343 from aaronfranke/negative-shape-warning

This commit is contained in:
Rémi Verschelde 2022-02-22 15:35:18 +01:00 committed by GitHub
commit 872e8a43ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 10 additions and 0 deletions

View File

@ -77,6 +77,7 @@ bool BoxShape3D::_get(const StringName &p_name, Variant &r_property) const {
#endif // DISABLE_DEPRECATED #endif // DISABLE_DEPRECATED
void BoxShape3D::set_size(const Vector3 &p_size) { void BoxShape3D::set_size(const Vector3 &p_size) {
ERR_FAIL_COND_MSG(p_size.x < 0 || p_size.y < 0 || p_size.z < 0, "BoxShape3D size cannot be negative.");
size = p_size; size = p_size;
_update_shape(); _update_shape();
notify_change_to_owners(); notify_change_to_owners();

View File

@ -59,6 +59,7 @@ void CapsuleShape2D::_update_shape() {
} }
void CapsuleShape2D::set_radius(real_t p_radius) { void CapsuleShape2D::set_radius(real_t p_radius) {
ERR_FAIL_COND_MSG(p_radius < 0, "CapsuleShape2D radius cannot be negative.");
radius = p_radius; radius = p_radius;
if (radius > height * 0.5) { if (radius > height * 0.5) {
height = radius * 2.0; height = radius * 2.0;
@ -71,6 +72,7 @@ real_t CapsuleShape2D::get_radius() const {
} }
void CapsuleShape2D::set_height(real_t p_height) { void CapsuleShape2D::set_height(real_t p_height) {
ERR_FAIL_COND_MSG(p_height < 0, "CapsuleShape2D height cannot be negative.");
height = p_height; height = p_height;
if (radius > height * 0.5) { if (radius > height * 0.5) {
radius = height * 0.5; radius = height * 0.5;

View File

@ -79,6 +79,7 @@ void CapsuleShape3D::_update_shape() {
} }
void CapsuleShape3D::set_radius(float p_radius) { void CapsuleShape3D::set_radius(float p_radius) {
ERR_FAIL_COND_MSG(p_radius < 0, "CapsuleShape3D radius cannot be negative.");
radius = p_radius; radius = p_radius;
if (radius > height * 0.5) { if (radius > height * 0.5) {
height = radius * 2.0; height = radius * 2.0;
@ -92,6 +93,7 @@ float CapsuleShape3D::get_radius() const {
} }
void CapsuleShape3D::set_height(float p_height) { void CapsuleShape3D::set_height(float p_height) {
ERR_FAIL_COND_MSG(p_height < 0, "CapsuleShape3D height cannot be negative.");
height = p_height; height = p_height;
if (radius > height * 0.5) { if (radius > height * 0.5) {
radius = height * 0.5; radius = height * 0.5;

View File

@ -43,6 +43,7 @@ void CircleShape2D::_update_shape() {
} }
void CircleShape2D::set_radius(real_t p_radius) { void CircleShape2D::set_radius(real_t p_radius) {
ERR_FAIL_COND_MSG(p_radius < 0, "CircleShape2D radius cannot be negative.");
radius = p_radius; radius = p_radius;
_update_shape(); _update_shape();
} }

View File

@ -72,6 +72,7 @@ void CylinderShape3D::_update_shape() {
} }
void CylinderShape3D::set_radius(float p_radius) { void CylinderShape3D::set_radius(float p_radius) {
ERR_FAIL_COND_MSG(p_radius < 0, "CylinderShape3D radius cannot be negative.");
radius = p_radius; radius = p_radius;
_update_shape(); _update_shape();
notify_change_to_owners(); notify_change_to_owners();
@ -82,6 +83,7 @@ float CylinderShape3D::get_radius() const {
} }
void CylinderShape3D::set_height(float p_height) { void CylinderShape3D::set_height(float p_height) {
ERR_FAIL_COND_MSG(p_height < 0, "CylinderShape3D height cannot be negative.");
height = p_height; height = p_height;
_update_shape(); _update_shape();
notify_change_to_owners(); notify_change_to_owners();

View File

@ -58,6 +58,7 @@ bool RectangleShape2D::_get(const StringName &p_name, Variant &r_property) const
#endif // DISABLE_DEPRECATED #endif // DISABLE_DEPRECATED
void RectangleShape2D::set_size(const Vector2 &p_size) { void RectangleShape2D::set_size(const Vector2 &p_size) {
ERR_FAIL_COND_MSG(p_size.x < 0 || p_size.y < 0, "RectangleShape2D size cannot be negative.");
size = p_size; size = p_size;
_update_shape(); _update_shape();
} }

View File

@ -63,6 +63,7 @@ void SphereShape3D::_update_shape() {
} }
void SphereShape3D::set_radius(float p_radius) { void SphereShape3D::set_radius(float p_radius) {
ERR_FAIL_COND_MSG(p_radius < 0, "SphereShape3D radius cannot be negative.");
radius = p_radius; radius = p_radius;
_update_shape(); _update_shape();
notify_change_to_owners(); notify_change_to_owners();