From c7a92f68a1796ea665e2d6116e879c027dde2725 Mon Sep 17 00:00:00 2001 From: smix8 <52464204+smix8@users.noreply.github.com> Date: Fri, 24 Feb 2023 00:36:30 +0100 Subject: [PATCH] Add error messages for collision exception functions Adds error messages to collision exception functions when used with the wrong object/node instead of failing silently. --- scene/2d/ray_cast_2d.cpp | 8 ++------ scene/2d/shape_cast_2d.cpp | 8 ++------ scene/3d/camera.cpp | 8 ++------ scene/3d/ray_cast.cpp | 8 ++------ scene/3d/shape_cast.cpp | 8 ++------ 5 files changed, 10 insertions(+), 30 deletions(-) diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index c1b3ca1f7e9..9d51d7d38ec 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -256,9 +256,7 @@ void RayCast2D::add_exception_rid(const RID &p_rid) { void RayCast2D::add_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject2D *co = Object::cast_to(p_object); - if (!co) { - return; - } + ERR_FAIL_COND_MSG(!co, "The passed Node must be an instance of CollisionObject2D."); add_exception_rid(co->get_rid()); } @@ -269,9 +267,7 @@ void RayCast2D::remove_exception_rid(const RID &p_rid) { void RayCast2D::remove_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject2D *co = Object::cast_to(p_object); - if (!co) { - return; - } + ERR_FAIL_COND_MSG(!co, "The passed Node must be an instance of CollisionObject2D."); remove_exception_rid(co->get_rid()); } diff --git a/scene/2d/shape_cast_2d.cpp b/scene/2d/shape_cast_2d.cpp index 0ad67017939..20e4376d26a 100644 --- a/scene/2d/shape_cast_2d.cpp +++ b/scene/2d/shape_cast_2d.cpp @@ -323,9 +323,7 @@ void ShapeCast2D::add_exception_rid(const RID &p_rid) { void ShapeCast2D::add_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject2D *co = Object::cast_to(p_object); - if (!co) { - return; - } + ERR_FAIL_COND_MSG(!co, "The passed Node must be an instance of CollisionObject2D."); add_exception_rid(co->get_rid()); } @@ -336,9 +334,7 @@ void ShapeCast2D::remove_exception_rid(const RID &p_rid) { void ShapeCast2D::remove_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject2D *co = Object::cast_to(p_object); - if (!co) { - return; - } + ERR_FAIL_COND_MSG(!co, "The passed Node must be an instance of CollisionObject2D."); remove_exception_rid(co->get_rid()); } diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index 9e1cca17b40..bf9341fe15b 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -797,9 +797,7 @@ void ClippedCamera::add_exception_rid(const RID &p_rid) { void ClippedCamera::add_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject *co = Object::cast_to(p_object); - if (!co) { - return; - } + ERR_FAIL_COND_MSG(!co, "The passed Node must be an instance of CollisionObject."); add_exception_rid(co->get_rid()); } @@ -810,9 +808,7 @@ void ClippedCamera::remove_exception_rid(const RID &p_rid) { void ClippedCamera::remove_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject *co = Object::cast_to(p_object); - if (!co) { - return; - } + ERR_FAIL_COND_MSG(!co, "The passed Node must be an instance of CollisionObject."); remove_exception_rid(co->get_rid()); } diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp index 331ea284be6..f6b3a487ceb 100644 --- a/scene/3d/ray_cast.cpp +++ b/scene/3d/ray_cast.cpp @@ -235,9 +235,7 @@ void RayCast::add_exception_rid(const RID &p_rid) { void RayCast::add_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject *co = Object::cast_to(p_object); - if (!co) { - return; - } + ERR_FAIL_COND_MSG(!co, "The passed Node must be an instance of CollisionObject."); add_exception_rid(co->get_rid()); } @@ -248,9 +246,7 @@ void RayCast::remove_exception_rid(const RID &p_rid) { void RayCast::remove_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject *co = Object::cast_to(p_object); - if (!co) { - return; - } + ERR_FAIL_COND_MSG(!co, "The passed Node must be an instance of CollisionObject."); remove_exception_rid(co->get_rid()); } diff --git a/scene/3d/shape_cast.cpp b/scene/3d/shape_cast.cpp index 6b7b33574af..4ecf6dadf1d 100644 --- a/scene/3d/shape_cast.cpp +++ b/scene/3d/shape_cast.cpp @@ -427,9 +427,7 @@ void ShapeCast::add_exception_rid(const RID &p_rid) { void ShapeCast::add_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject *co = Object::cast_to(p_object); - if (!co) { - return; - } + ERR_FAIL_COND_MSG(!co, "The passed Node must be an instance of CollisionObject."); add_exception_rid(co->get_rid()); } @@ -440,9 +438,7 @@ void ShapeCast::remove_exception_rid(const RID &p_rid) { void ShapeCast::remove_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject *co = Object::cast_to(p_object); - if (!co) { - return; - } + ERR_FAIL_COND_MSG(!co, "The passed Node must be an instance of CollisionObject."); remove_exception_rid(co->get_rid()); }