From 5a0cb54b3adbff7e63d7bcfb92a33bae1e55bdb0 Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Tue, 24 Jan 2023 10:46:53 +0000 Subject: [PATCH] Improve error messages and classref for occluders and portals Misused functions would previously produce no error messages which was confusing for users. --- doc/classes/OccluderShapePolygon.xml | 6 ++-- doc/classes/OccluderShapeSphere.xml | 4 +-- doc/classes/Portal.xml | 1 + doc/classes/Room.xml | 1 + scene/3d/portal.cpp | 4 +-- scene/3d/room.cpp | 4 +-- scene/resources/occluder_shape.cpp | 32 +++++++++++----------- scene/resources/occluder_shape_polygon.cpp | 8 ++---- 8 files changed, 28 insertions(+), 32 deletions(-) diff --git a/doc/classes/OccluderShapePolygon.xml b/doc/classes/OccluderShapePolygon.xml index b9c740b3202..7830c8e6303 100644 --- a/doc/classes/OccluderShapePolygon.xml +++ b/doc/classes/OccluderShapePolygon.xml @@ -17,7 +17,8 @@ - Sets an individual hole point position. + Sets an individual hole point position. Primarily for use by the editor. + [b]Note:[/b] This function will not resize the hole point array. Set [member hole_points] to set the number of points. @@ -25,7 +26,8 @@ - Sets an individual polygon point position. + Sets an individual polygon point position. Primarily for use by the editor. + [b]Note:[/b] This function will not resize the polygon point array. Set [member polygon_points] to set the number of points. diff --git a/doc/classes/OccluderShapeSphere.xml b/doc/classes/OccluderShapeSphere.xml index dc6346564c9..347eb92f080 100644 --- a/doc/classes/OccluderShapeSphere.xml +++ b/doc/classes/OccluderShapeSphere.xml @@ -15,7 +15,7 @@ - Sets an individual sphere's position. + Sets an individual sphere's position. Primarily for use by the editor. @@ -23,7 +23,7 @@ - Sets an individual sphere's radius. + Sets an individual sphere's radius. Primarily for use by the editor. diff --git a/doc/classes/Portal.xml b/doc/classes/Portal.xml index 3fd2bcae00a..5c7b30369df 100644 --- a/doc/classes/Portal.xml +++ b/doc/classes/Portal.xml @@ -18,6 +18,7 @@ Sets individual points. Primarily for use by the editor. + [b]Note:[/b] This function will not resize the point array. Set [member points] to set the number of points. diff --git a/doc/classes/Room.xml b/doc/classes/Room.xml index d8c38d8bc2b..6fb8fd283e5 100644 --- a/doc/classes/Room.xml +++ b/doc/classes/Room.xml @@ -19,6 +19,7 @@ Sets individual points. Primarily for use by the editor. + [b]Note:[/b] This function will not resize the point array. Set [member points] to set the number of points. diff --git a/scene/3d/portal.cpp b/scene/3d/portal.cpp index 669f088381b..a9940c67260 100644 --- a/scene/3d/portal.cpp +++ b/scene/3d/portal.cpp @@ -115,9 +115,7 @@ String Portal::get_configuration_warning() const { } void Portal::set_point(int p_idx, const Vector2 &p_point) { - if (p_idx >= _pts_local_raw.size()) { - return; - } + ERR_FAIL_INDEX_MSG(p_idx, _pts_local_raw.size(), "Index out of bounds. Call set_points() to set the size of the array."); _pts_local_raw.set(p_idx, p_point); _sanitize_points(); diff --git a/scene/3d/room.cpp b/scene/3d/room.cpp index 2713be4a9f1..0c0894acc67 100644 --- a/scene/3d/room.cpp +++ b/scene/3d/room.cpp @@ -131,9 +131,7 @@ void Room::set_use_default_simplify(bool p_use) { } void Room::set_point(int p_idx, const Vector3 &p_point) { - if (p_idx >= _bound_pts.size()) { - return; - } + ERR_FAIL_INDEX_MSG(p_idx, _bound_pts.size(), "Index out of bounds. Call set_points() to set the size of the array."); _bound_pts.set(p_idx, p_point); diff --git a/scene/resources/occluder_shape.cpp b/scene/resources/occluder_shape.cpp index 3288e562c3a..560161be122 100644 --- a/scene/resources/occluder_shape.cpp +++ b/scene/resources/occluder_shape.cpp @@ -210,29 +210,29 @@ void OccluderShapeSphere::set_spheres(const Vector &p_spheres) { } void OccluderShapeSphere::set_sphere_position(int p_idx, const Vector3 &p_position) { - if ((p_idx >= 0) && (p_idx < _spheres.size())) { - Plane p = _spheres[p_idx]; - p.normal = p_position; - _spheres.set(p_idx, p); + ERR_FAIL_INDEX(p_idx, _spheres.size()); + + Plane p = _spheres[p_idx]; + p.normal = p_position; + _spheres.set(p_idx, p); #ifdef TOOLS_ENABLED - _update_aabb(); + _update_aabb(); #endif - update_shape_to_visual_server(); - notify_change_to_owners(); - } + update_shape_to_visual_server(); + notify_change_to_owners(); } void OccluderShapeSphere::set_sphere_radius(int p_idx, real_t p_radius) { - if ((p_idx >= 0) && (p_idx < _spheres.size())) { - Plane p = _spheres[p_idx]; - p.d = MAX(p_radius, _min_radius); - _spheres.set(p_idx, p); + ERR_FAIL_INDEX(p_idx, _spheres.size()); + + Plane p = _spheres[p_idx]; + p.d = MAX(p_radius, _min_radius); + _spheres.set(p_idx, p); #ifdef TOOLS_ENABLED - _update_aabb(); + _update_aabb(); #endif - update_shape_to_visual_server(); - notify_change_to_owners(); - } + update_shape_to_visual_server(); + notify_change_to_owners(); } OccluderShapeSphere::OccluderShapeSphere() { diff --git a/scene/resources/occluder_shape_polygon.cpp b/scene/resources/occluder_shape_polygon.cpp index 970b235cf21..838194057c2 100644 --- a/scene/resources/occluder_shape_polygon.cpp +++ b/scene/resources/occluder_shape_polygon.cpp @@ -102,9 +102,7 @@ void OccluderShapePolygon::_sanitize_points() { } void OccluderShapePolygon::set_polygon_point(int p_idx, const Vector2 &p_point) { - if (p_idx >= _poly_pts_local_raw.size()) { - return; - } + ERR_FAIL_INDEX_MSG(p_idx, _poly_pts_local_raw.size(), "Index out of bounds. Call set_polygon_points() to set the size of the array."); _poly_pts_local_raw.set(p_idx, p_point); _sanitize_points(); @@ -113,9 +111,7 @@ void OccluderShapePolygon::set_polygon_point(int p_idx, const Vector2 &p_point) } void OccluderShapePolygon::set_hole_point(int p_idx, const Vector2 &p_point) { - if (p_idx >= _hole_pts_local_raw.size()) { - return; - } + ERR_FAIL_INDEX_MSG(p_idx, _hole_pts_local_raw.size(), "Index out of bounds. Call set_hole_points() to set the size of the array."); _hole_pts_local_raw.set(p_idx, p_point); _sanitize_points();