From dcd2b883eb1af68c4fdb5993a19126e1d6d4ba82 Mon Sep 17 00:00:00 2001 From: Ninni Pipping Date: Tue, 6 Jun 2023 14:59:54 +0200 Subject: [PATCH] Use NULL instead of COND checks when appropriate Restricted to scene --- scene/2d/area_2d.cpp | 8 ++++---- scene/2d/cpu_particles_2d.cpp | 2 +- scene/2d/node_2d.cpp | 2 +- scene/2d/physics_body_2d.cpp | 17 ++++++++--------- scene/2d/ray_cast_2d.cpp | 2 +- scene/2d/shape_cast_2d.cpp | 2 +- scene/2d/skeleton_2d.cpp | 2 +- scene/3d/area_3d.cpp | 8 ++++---- scene/3d/bone_attachment_3d.cpp | 10 +++++----- scene/3d/camera_3d.cpp | 4 ++-- scene/3d/cpu_particles_3d.cpp | 2 +- scene/3d/label_3d.cpp | 4 ++-- scene/3d/mesh_instance_3d.cpp | 6 +++--- scene/3d/node_3d.cpp | 12 ++++++------ scene/3d/occluder_instance_3d.cpp | 2 +- scene/3d/physics_body_3d.cpp | 17 ++++++++--------- scene/3d/ray_cast_3d.cpp | 2 +- scene/3d/shape_cast_3d.cpp | 2 +- scene/3d/skeleton_3d.cpp | 2 +- scene/3d/soft_body_3d.cpp | 4 ++-- scene/animation/animation_blend_tree.cpp | 2 +- scene/animation/animation_player.cpp | 4 ++-- scene/animation/animation_tree.cpp | 18 +++++++++--------- scene/debugger/scene_debugger.cpp | 2 +- scene/gui/container.cpp | 2 +- scene/gui/control.cpp | 6 +++--- scene/gui/graph_edit.cpp | 14 +++++++------- scene/gui/range.cpp | 2 +- scene/gui/rich_text_label.cpp | 2 +- scene/gui/tab_container.cpp | 4 ++-- scene/gui/tree.cpp | 12 ++++++------ scene/gui/video_stream_player.cpp | 4 ++-- scene/main/canvas_item.cpp | 6 +++--- scene/main/node.cpp | 18 +++++++++--------- scene/main/scene_tree.cpp | 10 +++++----- scene/main/viewport.cpp | 1 - scene/main/window.cpp | 6 +++--- scene/resources/importer_mesh.cpp | 4 ++-- scene/resources/mesh.cpp | 4 ++-- scene/resources/packed_scene.cpp | 6 +++--- .../skeleton_modification_2d_physicalbones.cpp | 2 +- scene/resources/texture.cpp | 8 ++++---- scene/resources/tile_set.cpp | 2 +- 43 files changed, 123 insertions(+), 126 deletions(-) diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 84877b13c22..2ea7a8d6aef 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -135,7 +135,7 @@ int Area2D::get_priority() const { void Area2D::_body_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!node); + ERR_FAIL_NULL(node); HashMap::Iterator E = body_map.find(p_id); ERR_FAIL_COND(!E); @@ -151,7 +151,7 @@ void Area2D::_body_enter_tree(ObjectID p_id) { void Area2D::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!node); + ERR_FAIL_NULL(node); HashMap::Iterator E = body_map.find(p_id); ERR_FAIL_COND(!E); ERR_FAIL_COND(!E->value.in_tree); @@ -231,7 +231,7 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i void Area2D::_area_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!node); + ERR_FAIL_NULL(node); HashMap::Iterator E = area_map.find(p_id); ERR_FAIL_COND(!E); @@ -247,7 +247,7 @@ void Area2D::_area_enter_tree(ObjectID p_id) { void Area2D::_area_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!node); + ERR_FAIL_NULL(node); HashMap::Iterator E = area_map.find(p_id); ERR_FAIL_COND(!E); ERR_FAIL_COND(!E->value.in_tree); diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index af943acb320..115104adff8 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -1163,7 +1163,7 @@ void CPUParticles2D::_notification(int p_what) { void CPUParticles2D::convert_from_particles(Node *p_particles) { GPUParticles2D *gpu_particles = Object::cast_to(p_particles); - ERR_FAIL_COND_MSG(!gpu_particles, "Only GPUParticles2D nodes can be converted to CPUParticles2D."); + ERR_FAIL_NULL_MSG(gpu_particles, "Only GPUParticles2D nodes can be converted to CPUParticles2D."); set_emitting(gpu_particles->is_emitting()); set_amount(gpu_particles->get_amount()); diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index a0eab67f289..4b7fad5edf0 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -403,7 +403,7 @@ Transform2D Node2D::get_relative_transform_to_parent(const Node *p_parent) const Node2D *parent_2d = Object::cast_to(get_parent()); - ERR_FAIL_COND_V(!parent_2d, Transform2D()); + ERR_FAIL_NULL_V(parent_2d, Transform2D()); if (p_parent == parent_2d) { return get_transform(); } else { diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 1b59351b303..b3acc1849be 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -162,14 +162,14 @@ TypedArray PhysicsBody2D::get_collision_exceptions() { void PhysicsBody2D::add_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); PhysicsBody2D *physics_body = Object::cast_to(p_node); - ERR_FAIL_COND_MSG(!physics_body, "Collision exception only works between two nodes that inherit from PhysicsBody2D."); + ERR_FAIL_NULL_MSG(physics_body, "Collision exception only works between two nodes that inherit from PhysicsBody2D."); PhysicsServer2D::get_singleton()->body_add_collision_exception(get_rid(), physics_body->get_rid()); } void PhysicsBody2D::remove_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); PhysicsBody2D *physics_body = Object::cast_to(p_node); - ERR_FAIL_COND_MSG(!physics_body, "Collision exception only works between two nodes that inherit from PhysicsBody2D."); + ERR_FAIL_NULL_MSG(physics_body, "Collision exception only works between two nodes that inherit from PhysicsBody2D."); PhysicsServer2D::get_singleton()->body_remove_collision_exception(get_rid(), physics_body->get_rid()); } @@ -323,9 +323,8 @@ AnimatableBody2D::AnimatableBody2D() : void RigidBody2D::_body_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!node); - - ERR_FAIL_COND(!contact_monitor); + ERR_FAIL_NULL(node); + ERR_FAIL_NULL(contact_monitor); HashMap::Iterator E = contact_monitor->body_map.find(p_id); ERR_FAIL_COND(!E); ERR_FAIL_COND(E->value.in_scene); @@ -345,8 +344,8 @@ void RigidBody2D::_body_enter_tree(ObjectID p_id) { void RigidBody2D::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!node); - ERR_FAIL_COND(!contact_monitor); + ERR_FAIL_NULL(node); + ERR_FAIL_NULL(contact_monitor); HashMap::Iterator E = contact_monitor->body_map.find(p_id); ERR_FAIL_COND(!E); ERR_FAIL_COND(!E->value.in_scene); @@ -370,7 +369,7 @@ void RigidBody2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instan Object *obj = ObjectDB::get_instance(objid); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!contact_monitor); + ERR_FAIL_NULL(contact_monitor); HashMap::Iterator E = contact_monitor->body_map.find(objid); ERR_FAIL_COND(!body_in && !E); @@ -849,7 +848,7 @@ RigidBody2D::CCDMode RigidBody2D::get_continuous_collision_detection_mode() cons } TypedArray RigidBody2D::get_colliding_bodies() const { - ERR_FAIL_COND_V(!contact_monitor, TypedArray()); + ERR_FAIL_NULL_V(contact_monitor, TypedArray()); TypedArray ret; ret.resize(contact_monitor->body_map.size()); diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index 988ea87054b..f27ac169b67 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -183,7 +183,7 @@ void RayCast2D::_update_raycast_state() { ERR_FAIL_COND(w2d.is_null()); PhysicsDirectSpaceState2D *dss = PhysicsServer2D::get_singleton()->space_get_direct_state(w2d->get_space()); - ERR_FAIL_COND(!dss); + ERR_FAIL_NULL(dss); Transform2D gt = get_global_transform(); diff --git a/scene/2d/shape_cast_2d.cpp b/scene/2d/shape_cast_2d.cpp index 5b743e0b319..f1a9119458c 100644 --- a/scene/2d/shape_cast_2d.cpp +++ b/scene/2d/shape_cast_2d.cpp @@ -293,7 +293,7 @@ void ShapeCast2D::_update_shapecast_state() { ERR_FAIL_COND(w2d.is_null()); PhysicsDirectSpaceState2D *dss = PhysicsServer2D::get_singleton()->space_get_direct_state(w2d->get_space()); - ERR_FAIL_COND(!dss); + ERR_FAIL_NULL(dss); Transform2D gt = get_global_transform(); diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp index f2270d2b18a..c31b42bebaf 100644 --- a/scene/2d/skeleton_2d.cpp +++ b/scene/2d/skeleton_2d.cpp @@ -406,7 +406,7 @@ void Bone2D::apply_rest() { } int Bone2D::get_index_in_skeleton() const { - ERR_FAIL_COND_V(!skeleton, -1); + ERR_FAIL_NULL_V(skeleton, -1); skeleton->_update_bone_setup(); return skeleton_index; } diff --git a/scene/3d/area_3d.cpp b/scene/3d/area_3d.cpp index 47912ad261d..fbf928f3f42 100644 --- a/scene/3d/area_3d.cpp +++ b/scene/3d/area_3d.cpp @@ -190,7 +190,7 @@ void Area3D::_initialize_wind() { void Area3D::_body_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!node); + ERR_FAIL_NULL(node); HashMap::Iterator E = body_map.find(p_id); ERR_FAIL_COND(!E); @@ -206,7 +206,7 @@ void Area3D::_body_enter_tree(ObjectID p_id) { void Area3D::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!node); + ERR_FAIL_NULL(node); HashMap::Iterator E = body_map.find(p_id); ERR_FAIL_COND(!E); ERR_FAIL_COND(!E->value.in_tree); @@ -379,7 +379,7 @@ void Area3D::set_monitoring(bool p_enable) { void Area3D::_area_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!node); + ERR_FAIL_NULL(node); HashMap::Iterator E = area_map.find(p_id); ERR_FAIL_COND(!E); @@ -395,7 +395,7 @@ void Area3D::_area_enter_tree(ObjectID p_id) { void Area3D::_area_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!node); + ERR_FAIL_NULL(node); HashMap::Iterator E = area_map.find(p_id); ERR_FAIL_COND(!E); ERR_FAIL_COND(!E->value.in_tree); diff --git a/scene/3d/bone_attachment_3d.cpp b/scene/3d/bone_attachment_3d.cpp index ba5ff028624..261bd401d4b 100644 --- a/scene/3d/bone_attachment_3d.cpp +++ b/scene/3d/bone_attachment_3d.cpp @@ -112,11 +112,11 @@ void BoneAttachment3D::_update_external_skeleton_cache() { external_skeleton_node_cache = ObjectID(); if (has_node(external_skeleton_node)) { Node *node = get_node(external_skeleton_node); - ERR_FAIL_COND_MSG(!node, "Cannot update external skeleton cache: Node cannot be found!"); + ERR_FAIL_NULL_MSG(node, "Cannot update external skeleton cache: Node cannot be found!"); // Make sure it's a skeleton3D Skeleton3D *sk = Object::cast_to(node); - ERR_FAIL_COND_MSG(!sk, "Cannot update external skeleton cache: Skeleton3D Nodepath does not point to a Skeleton3D node!"); + ERR_FAIL_NULL_MSG(sk, "Cannot update external skeleton cache: Skeleton3D Nodepath does not point to a Skeleton3D node!"); external_skeleton_node_cache = node->get_instance_id(); } else { @@ -126,11 +126,11 @@ void BoneAttachment3D::_update_external_skeleton_cache() { parent_attachment->_update_external_skeleton_cache(); if (parent_attachment->has_node(parent_attachment->external_skeleton_node)) { Node *node = parent_attachment->get_node(parent_attachment->external_skeleton_node); - ERR_FAIL_COND_MSG(!node, "Cannot update external skeleton cache: Parent's Skeleton3D node cannot be found!"); + ERR_FAIL_NULL_MSG(node, "Cannot update external skeleton cache: Parent's Skeleton3D node cannot be found!"); // Make sure it's a skeleton3D Skeleton3D *sk = Object::cast_to(node); - ERR_FAIL_COND_MSG(!sk, "Cannot update external skeleton cache: Parent Skeleton3D Nodepath does not point to a Skeleton3D node!"); + ERR_FAIL_NULL_MSG(sk, "Cannot update external skeleton cache: Parent Skeleton3D Nodepath does not point to a Skeleton3D node!"); external_skeleton_node_cache = node->get_instance_id(); external_skeleton_node = get_path_to(node); @@ -190,7 +190,7 @@ void BoneAttachment3D::_transform_changed() { if (override_pose) { Skeleton3D *sk = _get_skeleton3d(); - ERR_FAIL_COND_MSG(!sk, "Cannot override pose: Skeleton not found!"); + ERR_FAIL_NULL_MSG(sk, "Cannot override pose: Skeleton not found!"); ERR_FAIL_INDEX_MSG(bone_idx, sk->get_bone_count(), "Cannot override pose: Bone index is out of range!"); Transform3D our_trans = get_transform(); diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp index 47eb1eaa40c..5a4761892d1 100644 --- a/scene/3d/camera_3d.cpp +++ b/scene/3d/camera_3d.cpp @@ -106,7 +106,7 @@ void Camera3D::_notification(int p_what) { // and Spatial will handle it first, including clearing its reference to the Viewport, // therefore making it impossible to subclasses to access it viewport = get_viewport(); - ERR_FAIL_COND(!viewport); + ERR_FAIL_NULL(viewport); bool first_camera = viewport->_camera_3d_add(this); if (current || first_camera) { @@ -454,7 +454,7 @@ Ref Camera3D::get_attributes() const { void Camera3D::_attributes_changed() { CameraAttributesPhysical *physical_attributes = Object::cast_to(attributes.ptr()); - ERR_FAIL_COND(!physical_attributes); + ERR_FAIL_NULL(physical_attributes); fov = physical_attributes->get_fov(); near = physical_attributes->get_near(); diff --git a/scene/3d/cpu_particles_3d.cpp b/scene/3d/cpu_particles_3d.cpp index 72d16b345f7..405d478a475 100644 --- a/scene/3d/cpu_particles_3d.cpp +++ b/scene/3d/cpu_particles_3d.cpp @@ -1327,7 +1327,7 @@ void CPUParticles3D::_notification(int p_what) { void CPUParticles3D::convert_from_particles(Node *p_particles) { GPUParticles3D *gpu_particles = Object::cast_to(p_particles); - ERR_FAIL_COND_MSG(!gpu_particles, "Only GPUParticles3D nodes can be converted to CPUParticles3D."); + ERR_FAIL_NULL_MSG(gpu_particles, "Only GPUParticles3D nodes can be converted to CPUParticles3D."); set_emitting(gpu_particles->is_emitting()); set_amount(gpu_particles->get_amount()); diff --git a/scene/3d/label_3d.cpp b/scene/3d/label_3d.cpp index 198fb70ad75..810c0c53266 100644 --- a/scene/3d/label_3d.cpp +++ b/scene/3d/label_3d.cpp @@ -204,12 +204,12 @@ void Label3D::_notification(int p_what) { _im_update(); } Viewport *viewport = get_viewport(); - ERR_FAIL_COND(!viewport); + ERR_FAIL_NULL(viewport); viewport->connect("size_changed", callable_mp(this, &Label3D::_font_changed)); } break; case NOTIFICATION_EXIT_TREE: { Viewport *viewport = get_viewport(); - ERR_FAIL_COND(!viewport); + ERR_FAIL_NULL(viewport); viewport->disconnect("size_changed", callable_mp(this, &Label3D::_font_changed)); } break; case NOTIFICATION_TRANSLATION_CHANGED: { diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp index 0f7db64f5c4..28a3cd0b13d 100644 --- a/scene/3d/mesh_instance_3d.cpp +++ b/scene/3d/mesh_instance_3d.cpp @@ -243,7 +243,7 @@ Node *MeshInstance3D::create_trimesh_collision_node() { void MeshInstance3D::create_trimesh_collision() { StaticBody3D *static_body = Object::cast_to(create_trimesh_collision_node()); - ERR_FAIL_COND(!static_body); + ERR_FAIL_NULL(static_body); static_body->set_name(String(get_name()) + "_col"); add_child(static_body, true); @@ -273,7 +273,7 @@ Node *MeshInstance3D::create_convex_collision_node(bool p_clean, bool p_simplify void MeshInstance3D::create_convex_collision(bool p_clean, bool p_simplify) { StaticBody3D *static_body = Object::cast_to(create_convex_collision_node(p_clean, p_simplify)); - ERR_FAIL_COND(!static_body); + ERR_FAIL_NULL(static_body); static_body->set_name(String(get_name()) + "_col"); add_child(static_body, true); @@ -312,7 +312,7 @@ Node *MeshInstance3D::create_multiple_convex_collisions_node(const Ref &p_settings) { StaticBody3D *static_body = Object::cast_to(create_multiple_convex_collisions_node(p_settings)); - ERR_FAIL_COND(!static_body); + ERR_FAIL_NULL(static_body); static_body->set_name(String(get_name()) + "_col"); add_child(static_body, true); diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp index 4f2ee5a3b2d..932e4ea549f 100644 --- a/scene/3d/node_3d.cpp +++ b/scene/3d/node_3d.cpp @@ -135,7 +135,7 @@ void Node3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - ERR_FAIL_COND(!get_tree()); + ERR_FAIL_NULL(get_tree()); Node *p = get_parent(); if (p) { @@ -186,7 +186,7 @@ void Node3D::_notification(int p_what) { parent = parent->get_parent(); } - ERR_FAIL_COND(!data.viewport); + ERR_FAIL_NULL(data.viewport); if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_enter_world); @@ -379,7 +379,7 @@ Transform3D Node3D::get_relative_transform(const Node *p_parent) const { return Transform3D(); } - ERR_FAIL_COND_V(!data.parent, Transform3D()); + ERR_FAIL_NULL_V(data.parent, Transform3D()); if (p_parent == data.parent) { return get_transform(); @@ -743,7 +743,7 @@ bool Node3D::is_set_as_top_level() const { Ref Node3D::get_world_3d() const { ERR_READ_THREAD_GUARD_V(Ref()); // World3D can only be set from main thread, so it's safe to obtain on threads. ERR_FAIL_COND_V(!is_inside_world(), Ref()); - ERR_FAIL_COND_V(!data.viewport, Ref()); + ERR_FAIL_NULL_V(data.viewport, Ref()); return data.viewport->find_world_3d(); } @@ -977,10 +977,10 @@ void Node3D::_update_visibility_parent(bool p_update_root) { return; } Node *parent = get_node_or_null(visibility_parent_path); - ERR_FAIL_COND_MSG(!parent, "Can't find visibility parent node at path: " + visibility_parent_path); + ERR_FAIL_NULL_MSG(parent, "Can't find visibility parent node at path: " + visibility_parent_path); ERR_FAIL_COND_MSG(parent == this, "The visibility parent can't be the same node."); GeometryInstance3D *gi = Object::cast_to(parent); - ERR_FAIL_COND_MSG(!gi, "The visibility parent node must be a GeometryInstance3D, at path: " + visibility_parent_path); + ERR_FAIL_NULL_MSG(gi, "The visibility parent node must be a GeometryInstance3D, at path: " + visibility_parent_path); new_parent = gi ? gi->get_instance() : RID(); } else if (data.parent) { new_parent = data.parent->data.visibility_parent; diff --git a/scene/3d/occluder_instance_3d.cpp b/scene/3d/occluder_instance_3d.cpp index 594580a205b..8fd1df372b8 100644 --- a/scene/3d/occluder_instance_3d.cpp +++ b/scene/3d/occluder_instance_3d.cpp @@ -605,7 +605,7 @@ void OccluderInstance3D::_bake_node(Node *p_node, PackedVector3Array &r_vertices } void OccluderInstance3D::bake_single_node(const Node3D *p_node, float p_simplification_distance, PackedVector3Array &r_vertices, PackedInt32Array &r_indices) { - ERR_FAIL_COND(!p_node); + ERR_FAIL_NULL(p_node); Transform3D xform = p_node->is_inside_tree() ? p_node->get_global_transform() : p_node->get_transform(); diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index 4be695d189e..c8becc230b2 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -80,14 +80,14 @@ TypedArray PhysicsBody3D::get_collision_exceptions() { void PhysicsBody3D::add_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); CollisionObject3D *collision_object = Object::cast_to(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two nodes that inherit from CollisionObject3D (such as Area3D or PhysicsBody3D)."); + ERR_FAIL_NULL_MSG(collision_object, "Collision exception only works between two nodes that inherit from CollisionObject3D (such as Area3D or PhysicsBody3D)."); PhysicsServer3D::get_singleton()->body_add_collision_exception(get_rid(), collision_object->get_rid()); } void PhysicsBody3D::remove_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); CollisionObject3D *collision_object = Object::cast_to(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two nodes that inherit from CollisionObject3D (such as Area3D or PhysicsBody3D)."); + ERR_FAIL_NULL_MSG(collision_object, "Collision exception only works between two nodes that inherit from CollisionObject3D (such as Area3D or PhysicsBody3D)."); PhysicsServer3D::get_singleton()->body_remove_collision_exception(get_rid(), collision_object->get_rid()); } @@ -379,9 +379,8 @@ AnimatableBody3D::AnimatableBody3D() : void RigidBody3D::_body_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!node); - - ERR_FAIL_COND(!contact_monitor); + ERR_FAIL_NULL(node); + ERR_FAIL_NULL(contact_monitor); HashMap::Iterator E = contact_monitor->body_map.find(p_id); ERR_FAIL_COND(!E); ERR_FAIL_COND(E->value.in_tree); @@ -402,8 +401,8 @@ void RigidBody3D::_body_enter_tree(ObjectID p_id) { void RigidBody3D::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!node); - ERR_FAIL_COND(!contact_monitor); + ERR_FAIL_NULL(node); + ERR_FAIL_NULL(contact_monitor); HashMap::Iterator E = contact_monitor->body_map.find(p_id); ERR_FAIL_COND(!E); ERR_FAIL_COND(!E->value.in_tree); @@ -427,7 +426,7 @@ void RigidBody3D::_body_inout(int p_status, const RID &p_body, ObjectID p_instan Object *obj = ObjectDB::get_instance(objid); Node *node = Object::cast_to(obj); - ERR_FAIL_COND(!contact_monitor); + ERR_FAIL_NULL(contact_monitor); HashMap::Iterator E = contact_monitor->body_map.find(objid); ERR_FAIL_COND(!body_in && !E); @@ -962,7 +961,7 @@ bool RigidBody3D::is_contact_monitor_enabled() const { } TypedArray RigidBody3D::get_colliding_bodies() const { - ERR_FAIL_COND_V(!contact_monitor, TypedArray()); + ERR_FAIL_NULL_V(contact_monitor, TypedArray()); TypedArray ret; ret.resize(contact_monitor->body_map.size()); diff --git a/scene/3d/ray_cast_3d.cpp b/scene/3d/ray_cast_3d.cpp index c4e1f8e8d16..2dea6418ed2 100644 --- a/scene/3d/ray_cast_3d.cpp +++ b/scene/3d/ray_cast_3d.cpp @@ -206,7 +206,7 @@ void RayCast3D::_update_raycast_state() { ERR_FAIL_COND(w3d.is_null()); PhysicsDirectSpaceState3D *dss = PhysicsServer3D::get_singleton()->space_get_direct_state(w3d->get_space()); - ERR_FAIL_COND(!dss); + ERR_FAIL_NULL(dss); Transform3D gt = get_global_transform(); diff --git a/scene/3d/shape_cast_3d.cpp b/scene/3d/shape_cast_3d.cpp index 602eb664dd0..75f94b36d38 100644 --- a/scene/3d/shape_cast_3d.cpp +++ b/scene/3d/shape_cast_3d.cpp @@ -385,7 +385,7 @@ void ShapeCast3D::_update_shapecast_state() { ERR_FAIL_COND(w3d.is_null()); PhysicsDirectSpaceState3D *dss = PhysicsServer3D::get_singleton()->space_get_direct_state(w3d->get_space()); - ERR_FAIL_COND(!dss); + ERR_FAIL_NULL(dss); Transform3D gt = get_global_transform(); diff --git a/scene/3d/skeleton_3d.cpp b/scene/3d/skeleton_3d.cpp index ae73551007e..51359059ef0 100644 --- a/scene/3d/skeleton_3d.cpp +++ b/scene/3d/skeleton_3d.cpp @@ -680,7 +680,7 @@ void Skeleton3D::bind_physical_bone_to_bone(int p_bone, PhysicalBone3D *p_physic const int bone_size = bones.size(); ERR_FAIL_INDEX(p_bone, bone_size); ERR_FAIL_COND(bones[p_bone].physical_bone); - ERR_FAIL_COND(!p_physical_bone); + ERR_FAIL_NULL(p_physical_bone); bones.write[p_bone].physical_bone = p_physical_bone; _rebuild_physical_bones_cache(); diff --git a/scene/3d/soft_body_3d.cpp b/scene/3d/soft_body_3d.cpp index 9fa33e9d5ce..d1753fff6c8 100644 --- a/scene/3d/soft_body_3d.cpp +++ b/scene/3d/soft_body_3d.cpp @@ -593,14 +593,14 @@ TypedArray SoftBody3D::get_collision_exceptions() { void SoftBody3D::add_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); CollisionObject3D *collision_object = Object::cast_to(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two nodes that inherit from CollisionObject3D (such as Area3D or PhysicsBody3D)."); + ERR_FAIL_NULL_MSG(collision_object, "Collision exception only works between two nodes that inherit from CollisionObject3D (such as Area3D or PhysicsBody3D)."); PhysicsServer3D::get_singleton()->soft_body_add_collision_exception(physics_rid, collision_object->get_rid()); } void SoftBody3D::remove_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); CollisionObject3D *collision_object = Object::cast_to(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two nodes that inherit from CollisionObject3D (such as Area3D or PhysicsBody3D)."); + ERR_FAIL_NULL_MSG(collision_object, "Collision exception only works between two nodes that inherit from CollisionObject3D (such as Area3D or PhysicsBody3D)."); PhysicsServer3D::get_singleton()->soft_body_remove_collision_exception(physics_rid, collision_object->get_rid()); } diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index c1b1e6c287c..6a76b5ac168 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -66,7 +66,7 @@ void AnimationNodeAnimation::_validate_property(PropertyInfo &p_property) const double AnimationNodeAnimation::_process(double p_time, bool p_seek, bool p_is_external_seeking, bool p_test_only) { AnimationPlayer *ap = state->player; - ERR_FAIL_COND_V(!ap, 0); + ERR_FAIL_NULL_V(ap, 0); double cur_time = get_parameter(time); diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index ebf5d03a76d..f95a7f98bbf 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -273,7 +273,7 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim, Node *p_root_ov Node *parent = p_root_override ? p_root_override : get_node(root); - ERR_FAIL_COND(!parent); + ERR_FAIL_NULL(parent); Animation *a = p_anim->animation.operator->(); @@ -2169,7 +2169,7 @@ Ref AnimationPlayer::apply_reset(bool p_user_initiated) { ERR_FAIL_COND_V(reset_anim.is_null(), Ref()); Node *root_node = get_node_or_null(root); - ERR_FAIL_COND_V(!root_node, Ref()); + ERR_FAIL_NULL_V(root_node, Ref()); AnimationPlayer *aux_player = memnew(AnimationPlayer); EditorNode::get_singleton()->add_child(aux_player); diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index abd66905d19..23640328633 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -64,7 +64,7 @@ void AnimationNode::set_parameter(const StringName &p_name, const Variant &p_val if (is_testing) { return; } - ERR_FAIL_COND(!state); + ERR_FAIL_NULL(state); ERR_FAIL_COND(!state->tree->property_parent_map.has(base_path)); ERR_FAIL_COND(!state->tree->property_parent_map[base_path].has(p_name)); StringName path = state->tree->property_parent_map[base_path][p_name]; @@ -73,7 +73,7 @@ void AnimationNode::set_parameter(const StringName &p_name, const Variant &p_val } Variant AnimationNode::get_parameter(const StringName &p_name) const { - ERR_FAIL_COND_V(!state, Variant()); + ERR_FAIL_NULL_V(state, Variant()); ERR_FAIL_COND_V(!state->tree->property_parent_map.has(base_path), Variant()); ERR_FAIL_COND_V(!state->tree->property_parent_map[base_path].has(p_name), Variant()); @@ -96,7 +96,7 @@ void AnimationNode::get_child_nodes(List *r_child_nodes) { } void AnimationNode::blend_animation(const StringName &p_animation, double p_time, double p_delta, bool p_seeked, bool p_is_external_seeking, real_t p_blend, Animation::LoopedFlag p_looped_flag) { - ERR_FAIL_COND(!state); + ERR_FAIL_NULL(state); ERR_FAIL_COND(!state->player->has_animation(p_animation)); Ref animation = state->player->get_animation(p_animation); @@ -144,12 +144,12 @@ double AnimationNode::_pre_process(const StringName &p_base_path, AnimationNode } AnimationTree *AnimationNode::get_animation_tree() const { - ERR_FAIL_COND_V(!state, nullptr); + ERR_FAIL_NULL_V(state, nullptr); return state->tree; } void AnimationNode::make_invalid(const String &p_reason) { - ERR_FAIL_COND(!state); + ERR_FAIL_NULL(state); state->valid = false; if (!state->invalid_reasons.is_empty()) { state->invalid_reasons += "\n"; @@ -159,10 +159,10 @@ void AnimationNode::make_invalid(const String &p_reason) { double AnimationNode::blend_input(int p_input, double p_time, bool p_seek, bool p_is_external_seeking, real_t p_blend, FilterAction p_filter, bool p_sync, bool p_test_only) { ERR_FAIL_INDEX_V(p_input, inputs.size(), 0); - ERR_FAIL_COND_V(!state, 0); + ERR_FAIL_NULL_V(state, 0); AnimationNodeBlendTree *blend_tree = Object::cast_to(parent); - ERR_FAIL_COND_V(!blend_tree, 0); + ERR_FAIL_NULL_V(blend_tree, 0); StringName node_name = connections[p_input]; @@ -193,7 +193,7 @@ double AnimationNode::blend_node(const StringName &p_sub_path, Ref &p_connections, AnimationNode *p_new_parent, Ref p_node, double p_time, bool p_seek, bool p_is_external_seeking, real_t p_blend, FilterAction p_filter, bool p_sync, real_t *r_max, bool p_test_only) { ERR_FAIL_COND_V(!p_node.is_valid(), 0); - ERR_FAIL_COND_V(!state, 0); + ERR_FAIL_NULL_V(state, 0); int blend_count = blends.size(); @@ -293,7 +293,7 @@ double AnimationNode::_blend_node(const StringName &p_subpath, const Vectorbase_path) + String(p_subpath) + "/"; } diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index 6df40837c5a..391388fc04d 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -221,7 +221,7 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra void SceneDebugger::_save_node(ObjectID id, const String &p_path) { Node *node = Object::cast_to(ObjectDB::get_instance(id)); - ERR_FAIL_COND(!node); + ERR_FAIL_NULL(node); #ifdef TOOLS_ENABLED HashMap duplimap; diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp index 145074a626f..2abd8cdf030 100644 --- a/scene/gui/container.cpp +++ b/scene/gui/container.cpp @@ -97,7 +97,7 @@ void Container::_sort_children() { } void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) { - ERR_FAIL_COND(!p_child); + ERR_FAIL_NULL(p_child); ERR_FAIL_COND(p_child->get_parent() != this); bool rtl = is_layout_rtl(); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index e34309df48c..160d55bf9bb 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -3180,7 +3180,7 @@ void Control::_notification(int p_notification) { } else { // Is a regular root control or top_level. Viewport *viewport = get_viewport(); - ERR_FAIL_COND(!viewport); + ERR_FAIL_NULL(viewport); data.RI = viewport->_gui_add_root_control(this); get_parent()->connect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::gui_set_root_order_dirty), CONNECT_REFERENCE_COUNTED); @@ -3193,7 +3193,7 @@ void Control::_notification(int p_notification) { } else { // Connect viewport. Viewport *viewport = get_viewport(); - ERR_FAIL_COND(!viewport); + ERR_FAIL_NULL(viewport); viewport->connect("size_changed", callable_mp(this, &Control::_size_changed)); } } break; @@ -3205,7 +3205,7 @@ void Control::_notification(int p_notification) { } else { // Disconnect viewport. Viewport *viewport = get_viewport(); - ERR_FAIL_COND(!viewport); + ERR_FAIL_NULL(viewport); viewport->disconnect("size_changed", callable_mp(this, &Control::_size_changed)); } diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index f2f98b18897..be9195e9dc4 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -372,7 +372,7 @@ void GraphEdit::_update_scroll() { void GraphEdit::_graph_node_raised(Node *p_gn) { GraphNode *gn = Object::cast_to(p_gn); - ERR_FAIL_COND(!gn); + ERR_FAIL_NULL(gn); if (gn->is_comment()) { move_child(gn, 0); } else { @@ -382,21 +382,21 @@ void GraphEdit::_graph_node_raised(Node *p_gn) { void GraphEdit::_graph_node_selected(Node *p_gn) { GraphNode *gn = Object::cast_to(p_gn); - ERR_FAIL_COND(!gn); + ERR_FAIL_NULL(gn); emit_signal(SNAME("node_selected"), gn); } void GraphEdit::_graph_node_deselected(Node *p_gn) { GraphNode *gn = Object::cast_to(p_gn); - ERR_FAIL_COND(!gn); + ERR_FAIL_NULL(gn); emit_signal(SNAME("node_deselected"), gn); } void GraphEdit::_graph_node_moved(Node *p_gn) { GraphNode *gn = Object::cast_to(p_gn); - ERR_FAIL_COND(!gn); + ERR_FAIL_NULL(gn); top_layer->queue_redraw(); minimap->queue_redraw(); queue_redraw(); @@ -405,7 +405,7 @@ void GraphEdit::_graph_node_moved(Node *p_gn) { void GraphEdit::_graph_node_slot_updated(int p_index, Node *p_gn) { GraphNode *gn = Object::cast_to(p_gn); - ERR_FAIL_COND(!gn); + ERR_FAIL_NULL(gn); top_layer->queue_redraw(); minimap->queue_redraw(); queue_redraw(); @@ -990,9 +990,9 @@ void GraphEdit::_top_layer_draw() { if (connecting) { Node *fromn = get_node(NodePath(connecting_from)); - ERR_FAIL_COND(!fromn); + ERR_FAIL_NULL(fromn); GraphNode *from = Object::cast_to(fromn); - ERR_FAIL_COND(!from); + ERR_FAIL_NULL(from); Vector2 pos; if (connecting_out) { pos = from->get_connection_output_position(connecting_index); diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index 97a1483204c..8db4fe42efb 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -236,7 +236,7 @@ double Range::get_as_ratio() const { void Range::_share(Node *p_range) { Range *r = Object::cast_to(p_range); - ERR_FAIL_COND(!r); + ERR_FAIL_NULL(r); share(r); } diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 6f3b7d140ee..6073329e508 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -3599,7 +3599,7 @@ void RichTextLabel::pop() { _stop_thread(); MutexLock data_lock(data_mutex); - ERR_FAIL_COND(!current->parent); + ERR_FAIL_NULL(current->parent); if (current->type == ITEM_FRAME) { current_frame = static_cast(current)->parent_frame; diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 1b148defc16..a6be8f29488 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -731,7 +731,7 @@ bool TabContainer::is_all_tabs_in_front() const { void TabContainer::set_tab_title(int p_tab, const String &p_title) { Control *child = get_tab_control(p_tab); - ERR_FAIL_COND(!child); + ERR_FAIL_NULL(child); if (tab_bar->get_tab_title(p_tab) == p_title) { return; @@ -789,7 +789,7 @@ bool TabContainer::is_tab_disabled(int p_tab) const { void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) { Control *child = get_tab_control(p_tab); - ERR_FAIL_COND(!child); + ERR_FAIL_NULL(child); if (tab_bar->is_tab_hidden(p_tab) == p_hidden) { return; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index c6584eec757..a5d12aecadf 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -992,7 +992,7 @@ void TreeItem::validate_cache() const { void TreeItem::move_before(TreeItem *p_item) { ERR_FAIL_NULL(p_item); ERR_FAIL_COND(is_root); - ERR_FAIL_COND(!p_item->parent); + ERR_FAIL_NULL(p_item->parent); if (p_item == this) { return; @@ -1037,7 +1037,7 @@ void TreeItem::move_before(TreeItem *p_item) { void TreeItem::move_after(TreeItem *p_item) { ERR_FAIL_NULL(p_item); ERR_FAIL_COND(is_root); - ERR_FAIL_COND(!p_item->parent); + ERR_FAIL_NULL(p_item->parent); if (p_item == this) { return; @@ -1400,7 +1400,7 @@ bool TreeItem::is_folding_disabled() const { Size2 TreeItem::get_minimum_size(int p_column) { ERR_FAIL_INDEX_V(p_column, cells.size(), Size2()); Tree *parent_tree = get_tree(); - ERR_FAIL_COND_V(!parent_tree, Size2()); + ERR_FAIL_NULL_V(parent_tree, Size2()); const TreeItem::Cell &cell = cells[p_column]; @@ -3916,7 +3916,7 @@ void Tree::gui_input(const Ref &p_event) { bool Tree::edit_selected(bool p_force_edit) { TreeItem *s = get_selected(); - ERR_FAIL_COND_V_MSG(!s, false, "No item selected."); + ERR_FAIL_NULL_V_MSG(s, false, "No item selected."); ensure_cursor_is_visible(); int col = get_selected_column(); ERR_FAIL_INDEX_V_MSG(col, columns.size(), false, "No item column selected."); @@ -4338,7 +4338,7 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_index) { if (!root) { // No root exists, make the given item the new root. ti = memnew(TreeItem(this)); - ERR_FAIL_COND_V(!ti, nullptr); + ERR_FAIL_NULL_V(ti, nullptr); ti->cells.resize(columns.size()); ti->is_root = true; root = ti; @@ -4572,7 +4572,7 @@ TreeItem *Tree::get_selected() const { void Tree::set_selected(TreeItem *p_item, int p_column) { ERR_FAIL_INDEX(p_column, columns.size()); - ERR_FAIL_COND(!p_item); + ERR_FAIL_NULL(p_item); select_single_item(p_item, get_root(), p_column); } diff --git a/scene/gui/video_stream_player.cpp b/scene/gui/video_stream_player.cpp index 1381e5be89c..19a54e01c4c 100644 --- a/scene/gui/video_stream_player.cpp +++ b/scene/gui/video_stream_player.cpp @@ -103,7 +103,7 @@ void VideoStreamPlayer::_mix_audio() { if (cc == 1) { AudioFrame *target = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, 0); - ERR_FAIL_COND(!target); + ERR_FAIL_NULL(target); for (int j = 0; j < buffer_size; j++) { target[j] += buffer[j] * vol; @@ -114,7 +114,7 @@ void VideoStreamPlayer::_mix_audio() { for (int k = 0; k < cc; k++) { targets[k] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index, k); - ERR_FAIL_COND(!targets[k]); + ERR_FAIL_NULL(targets[k]); } for (int j = 0; j < buffer_size; j++) { diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index ae01e8b0097..f0cffa2a78b 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -381,7 +381,7 @@ void CanvasItem::update_draw_order() { if (canvas_group != StringName()) { get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE | SceneTree::GROUP_CALL_DEFERRED, canvas_group, "_top_level_raise_self"); } else { - ERR_FAIL_COND_MSG(!get_parent_item(), "Moved child is in incorrect state (no canvas group, no canvas item parent)."); + ERR_FAIL_NULL_MSG(get_parent_item(), "Moved child is in incorrect state (no canvas group, no canvas item parent)."); RenderingServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index()); } } @@ -1033,13 +1033,13 @@ Ref CanvasItem::make_input_local(const Ref &p_event) con Vector2 CanvasItem::get_global_mouse_position() const { ERR_READ_THREAD_GUARD_V(Vector2()); - ERR_FAIL_COND_V(!get_viewport(), Vector2()); + ERR_FAIL_NULL_V(get_viewport(), Vector2()); return get_canvas_transform().affine_inverse().xform(get_viewport()->get_mouse_position()); } Vector2 CanvasItem::get_local_mouse_position() const { ERR_READ_THREAD_GUARD_V(Vector2()); - ERR_FAIL_COND_V(!get_viewport(), Vector2()); + ERR_FAIL_NULL_V(get_viewport(), Vector2()); return get_global_transform().affine_inverse().xform(get_global_mouse_position()); } diff --git a/scene/main/node.cpp b/scene/main/node.cpp index a9fff264e4a..d97e6681727 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -66,8 +66,8 @@ void Node::_notification(int p_notification) { } break; case NOTIFICATION_ENTER_TREE: { - ERR_FAIL_COND(!get_viewport()); - ERR_FAIL_COND(!get_tree()); + ERR_FAIL_NULL(get_viewport()); + ERR_FAIL_NULL(get_tree()); // Update process mode. if (data.process_mode == PROCESS_MODE_INHERIT) { @@ -121,8 +121,8 @@ void Node::_notification(int p_notification) { } break; case NOTIFICATION_EXIT_TREE: { - ERR_FAIL_COND(!get_viewport()); - ERR_FAIL_COND(!get_tree()); + ERR_FAIL_NULL(get_viewport()); + ERR_FAIL_NULL(get_tree()); get_tree()->nodes_in_tree_count--; orphan_node_count++; @@ -1989,7 +1989,7 @@ NodePath Node::get_path_to(const Node *p_node, bool p_use_unique_path) const { common_parent = common_parent->data.parent; } - ERR_FAIL_COND_V(!common_parent, NodePath()); //nodes not in the same tree + ERR_FAIL_NULL_V(common_parent, NodePath()); //nodes not in the same tree visited.clear(); @@ -2252,7 +2252,7 @@ void Node::_propagate_replace_owner(Node *p_owner, Node *p_by_owner) { Ref Node::create_tween() { ERR_THREAD_GUARD_V(Ref()); - ERR_FAIL_COND_V_MSG(!data.tree, nullptr, "Can't create Tween when not inside scene tree."); + ERR_FAIL_NULL_V_MSG(data.tree, nullptr, "Can't create Tween when not inside scene tree."); Ref tween = get_tree()->create_tween(); tween->bind_node(this); return tween; @@ -2437,19 +2437,19 @@ Node *Node::_duplicate(int p_flags, HashMap *r_duplimap) c } #endif node = res->instantiate(edit_state); - ERR_FAIL_COND_V(!node, nullptr); + ERR_FAIL_NULL_V(node, nullptr); node->set_scene_instance_load_placeholder(get_scene_instance_load_placeholder()); instantiated = true; } else { Object *obj = ClassDB::instantiate(get_class()); - ERR_FAIL_COND_V(!obj, nullptr); + ERR_FAIL_NULL_V(obj, nullptr); node = Object::cast_to(obj); if (!node) { memdelete(obj); } - ERR_FAIL_COND_V(!node, nullptr); + ERR_FAIL_NULL_V(node, nullptr); } if (!get_scene_file_path().is_empty()) { //an instance diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 7c43368f961..e071011c48d 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -443,7 +443,7 @@ void SceneTree::set_group(const StringName &p_group, const String &p_name, const } void SceneTree::initialize() { - ERR_FAIL_COND(!root); + ERR_FAIL_NULL(root); initialized = true; root->_set_tree(this); MainLoop::initialize(); @@ -1095,7 +1095,7 @@ bool SceneTree::ProcessGroupSort::operator()(const ProcessGroup *p_left, const P void SceneTree::_remove_process_group(Node *p_node) { _THREAD_SAFE_METHOD_ ProcessGroup *pg = (ProcessGroup *)p_node->data.process_group; - ERR_FAIL_COND(!pg); + ERR_FAIL_NULL(pg); ERR_FAIL_COND(pg->removed); pg->removed = true; pg->owner = nullptr; @@ -1105,7 +1105,7 @@ void SceneTree::_remove_process_group(Node *p_node) { void SceneTree::_add_process_group(Node *p_node) { _THREAD_SAFE_METHOD_ - ERR_FAIL_COND(!p_node); + ERR_FAIL_NULL(p_node); ProcessGroup *pg = memnew(ProcessGroup); @@ -1419,7 +1419,7 @@ Error SceneTree::change_scene_to_packed(const Ref &p_scene) { ERR_FAIL_COND_V_MSG(p_scene.is_null(), ERR_INVALID_PARAMETER, "Can't change to a null scene. Use unload_current_scene() if you wish to unload it."); Node *new_scene = p_scene->instantiate(); - ERR_FAIL_COND_V(!new_scene, ERR_CANT_CREATE); + ERR_FAIL_NULL_V(new_scene, ERR_CANT_CREATE); call_deferred(SNAME("_change_scene"), new_scene); return OK; @@ -1427,7 +1427,7 @@ Error SceneTree::change_scene_to_packed(const Ref &p_scene) { Error SceneTree::reload_current_scene() { ERR_FAIL_COND_V_MSG(!Thread::is_main_thread(), ERR_INVALID_PARAMETER, "Reloading scene can only be done from the main thread."); - ERR_FAIL_COND_V(!current_scene, ERR_UNCONFIGURED); + ERR_FAIL_NULL_V(current_scene, ERR_UNCONFIGURED); String fname = current_scene->get_scene_file_path(); return change_scene_to_file(fname); } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 38759b85b9a..66bd60cc67f 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2317,7 +2317,6 @@ void Viewport::_gui_force_drag(Control *p_base, const Variant &p_data, Control * void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) { ERR_FAIL_NULL(p_control); - ERR_FAIL_COND(!Object::cast_to((Object *)p_control)); ERR_FAIL_COND(p_control->is_inside_tree()); ERR_FAIL_COND(p_control->get_parent() != nullptr); diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 3a906fd989a..b82b215e546 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -1774,7 +1774,7 @@ Rect2i Window::get_usable_parent_rect() const { } else { const Window *w = is_visible() ? this : get_parent_visible_window(); //find a parent that can contain us - ERR_FAIL_COND_V(!w, Rect2()); + ERR_FAIL_NULL_V(w, Rect2()); parent_rect = DisplayServer::get_singleton()->screen_get_usable_rect(DisplayServer::get_singleton()->window_get_current_screen(w->get_window_id())); } @@ -2335,9 +2335,9 @@ Rect2i Window::get_parent_rect() const { if (is_embedded()) { //viewport Node *n = get_parent(); - ERR_FAIL_COND_V(!n, Rect2i()); + ERR_FAIL_NULL_V(n, Rect2i()); Viewport *p = n->get_viewport(); - ERR_FAIL_COND_V(!p, Rect2i()); + ERR_FAIL_NULL_V(p, Rect2i()); return p->get_visible_rect(); } else { diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp index 09738757fd4..24e8bf7ae73 100644 --- a/scene/resources/importer_mesh.cpp +++ b/scene/resources/importer_mesh.cpp @@ -939,7 +939,7 @@ Vector ImporterMesh::get_faces() const { } Vector> ImporterMesh::convex_decompose(const Ref &p_settings) const { - ERR_FAIL_COND_V(!Mesh::convex_decomposition_function, Vector>()); + ERR_FAIL_NULL_V(Mesh::convex_decomposition_function, Vector>()); const Vector faces = get_faces(); int face_count = faces.size(); @@ -1102,7 +1102,7 @@ struct EditorSceneFormatImporterMeshLightmapSurface { static const uint32_t custom_shift[RS::ARRAY_CUSTOM_COUNT] = { Mesh::ARRAY_FORMAT_CUSTOM0_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM1_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM2_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM3_SHIFT }; Error ImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform, float p_texel_size, const Vector &p_src_cache, Vector &r_dst_cache) { - ERR_FAIL_COND_V(!array_mesh_lightmap_unwrap_callback, ERR_UNCONFIGURED); + ERR_FAIL_NULL_V(array_mesh_lightmap_unwrap_callback, ERR_UNCONFIGURED); ERR_FAIL_COND_V_MSG(blend_shapes.size() != 0, ERR_UNAVAILABLE, "Can't unwrap mesh with blend shapes."); LocalVector vertices; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 81192fa8d50..80927570273 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -895,7 +895,7 @@ void Mesh::clear_cache() const { } Vector> Mesh::convex_decompose(const Ref &p_settings) const { - ERR_FAIL_COND_V(!convex_decomposition_function, Vector>()); + ERR_FAIL_NULL_V(convex_decomposition_function, Vector>()); Ref tm = generate_triangle_mesh(); ERR_FAIL_COND_V(!tm.is_valid(), Vector>()); @@ -2014,7 +2014,7 @@ Error ArrayMesh::lightmap_unwrap(const Transform3D &p_base_transform, float p_te } Error ArrayMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform, float p_texel_size, const Vector &p_src_cache, Vector &r_dst_cache, bool p_generate_cache) { - ERR_FAIL_COND_V(!array_mesh_lightmap_unwrap_callback, ERR_UNCONFIGURED); + ERR_FAIL_NULL_V(array_mesh_lightmap_unwrap_callback, ERR_UNCONFIGURED); ERR_FAIL_COND_V_MSG(blend_shapes.size() != 0, ERR_UNAVAILABLE, "Can't unwrap mesh with blend shapes."); ERR_FAIL_COND_V_MSG(p_texel_size <= 0.0f, ERR_PARAMETER_RANGE_ERROR, "Texel size must be greater than 0."); diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 4d690bd3b1c..4686ad41966 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -142,7 +142,7 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const { Ref sdata = props[base_scene_idx]; ERR_FAIL_COND_V(!sdata.is_valid(), nullptr); node = sdata->instantiate(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); //only main gets main edit state - ERR_FAIL_COND_V(!node, nullptr); + ERR_FAIL_NULL_V(node, nullptr); if (p_edit_state != GEN_EDIT_STATE_DISABLED) { node->set_scene_inherited_state(sdata->get_state()); } @@ -155,7 +155,7 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const { Ref sdata = ResourceLoader::load(scene_path, "PackedScene"); ERR_FAIL_COND_V(!sdata.is_valid(), nullptr); node = sdata->instantiate(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); - ERR_FAIL_COND_V(!node, nullptr); + ERR_FAIL_NULL_V(node, nullptr); } else { InstancePlaceholder *ip = memnew(InstancePlaceholder); ip->set_instance_path(scene_path); @@ -166,7 +166,7 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const { Ref sdata = props[n.instance & FLAG_MASK]; ERR_FAIL_COND_V(!sdata.is_valid(), nullptr); node = sdata->instantiate(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); - ERR_FAIL_COND_V(!node, nullptr); + ERR_FAIL_NULL_V(node, nullptr); } } else if (n.type == TYPE_INSTANTIATED) { diff --git a/scene/resources/skeleton_modification_2d_physicalbones.cpp b/scene/resources/skeleton_modification_2d_physicalbones.cpp index 818d84dffb2..520b2ce4831 100644 --- a/scene/resources/skeleton_modification_2d_physicalbones.cpp +++ b/scene/resources/skeleton_modification_2d_physicalbones.cpp @@ -185,7 +185,7 @@ void SkeletonModification2DPhysicalBones::set_physical_bone_chain_length(int p_l } void SkeletonModification2DPhysicalBones::fetch_physical_bones() { - ERR_FAIL_COND_MSG(!stack, "No modification stack found! Cannot fetch physical bones!"); + ERR_FAIL_NULL_MSG(stack, "No modification stack found! Cannot fetch physical bones!"); ERR_FAIL_COND_MSG(!stack->skeleton, "No skeleton found! Cannot fetch physical bones!"); physical_bone_chain.clear(); diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index bc084e7dbb8..b0449f0a26b 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -386,7 +386,7 @@ void PortableCompressedTexture2D::_set_data(const Vector &p_data) { } break; case COMPRESSION_MODE_BASIS_UNIVERSAL: { - ERR_FAIL_COND(!Image::basis_universal_unpacker_ptr); + ERR_FAIL_NULL(Image::basis_universal_unpacker_ptr); image = Image::basis_universal_unpacker_ptr(data, data_size); } break; @@ -812,21 +812,21 @@ void CompressedTexture2D::set_path(const String &p_path, bool p_take_over) { void CompressedTexture2D::_requested_3d(void *p_ud) { CompressedTexture2D *ct = (CompressedTexture2D *)p_ud; Ref ctex(ct); - ERR_FAIL_COND(!request_3d_callback); + ERR_FAIL_NULL(request_3d_callback); request_3d_callback(ctex); } void CompressedTexture2D::_requested_roughness(void *p_ud, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel) { CompressedTexture2D *ct = (CompressedTexture2D *)p_ud; Ref ctex(ct); - ERR_FAIL_COND(!request_roughness_callback); + ERR_FAIL_NULL(request_roughness_callback); request_roughness_callback(ctex, p_normal_path, p_roughness_channel); } void CompressedTexture2D::_requested_normal(void *p_ud) { CompressedTexture2D *ct = (CompressedTexture2D *)p_ud; Ref ctex(ct); - ERR_FAIL_COND(!request_normal_callback); + ERR_FAIL_NULL(request_normal_callback); request_normal_callback(ctex); } diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index efe04ce4e1b..ec9f4806a07 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -1610,7 +1610,7 @@ Vector TileSet::get_terrain_peering_bit_polygon(int p_terrain_set, TileS #define TERRAIN_ALPHA 0.6 void TileSet::draw_terrains(CanvasItem *p_canvas_item, Transform2D p_transform, const TileData *p_tile_data) { - ERR_FAIL_COND(!p_tile_data); + ERR_FAIL_NULL(p_tile_data); if (terrain_bits_meshes_dirty) { // Recompute the meshes.