[Scene,Main] Replace ERR_FAIL_COND with ERR_FAIL_NULL where applicable

This commit is contained in:
A Thousand Ships 2023-09-09 17:52:40 +02:00
parent 98b50eb308
commit a29416e332
15 changed files with 31 additions and 31 deletions

View file

@ -289,7 +289,7 @@ void initialize_physics() {
// Physics server not found, Use the default physics
physics_server_3d = PhysicsServer3DManager::get_singleton()->new_default_server();
}
ERR_FAIL_COND(!physics_server_3d);
ERR_FAIL_NULL(physics_server_3d);
physics_server_3d->init();
// 2D Physics server
@ -299,7 +299,7 @@ void initialize_physics() {
// Physics server not found, Use the default physics
physics_server_2d = PhysicsServer2DManager::get_singleton()->new_default_server();
}
ERR_FAIL_COND(!physics_server_2d);
ERR_FAIL_NULL(physics_server_2d);
physics_server_2d->init();
}
@ -3022,7 +3022,7 @@ bool Main::start() {
return false;
} else {
Object *ml = ClassDB::instantiate(main_loop_type);
ERR_FAIL_COND_V_MSG(!ml, false, "Can't instance MainLoop type.");
ERR_FAIL_NULL_V_MSG(ml, false, "Can't instance MainLoop type.");
main_loop = Object::cast_to<MainLoop>(ml);
if (!main_loop) {
@ -3302,7 +3302,7 @@ bool Main::start() {
scene = scenedata->instantiate();
}
ERR_FAIL_COND_V_MSG(!scene, false, "Failed loading scene: " + local_game_path);
ERR_FAIL_NULL_V_MSG(scene, false, "Failed loading scene: " + local_game_path + ".");
sml->add_current_scene(scene);
#ifdef MACOS_ENABLED

View file

@ -447,7 +447,7 @@ void AnimatedSprite2D::play(const StringName &p_name, float p_custom_scale, bool
name = animation;
}
ERR_FAIL_COND_MSG(frames == nullptr, vformat("There is no animation with name '%s'.", name));
ERR_FAIL_NULL_MSG(frames, vformat("There is no animation with name '%s'.", name));
ERR_FAIL_COND_MSG(!frames->get_animation_names().has(name), vformat("There is no animation with name '%s'.", name));
if (frames->get_frame_count(name) == 0) {

View file

@ -119,7 +119,7 @@ StringName AudioStreamPlayer2D::_get_actual_bus() {
ERR_FAIL_COND_V(world_2d.is_null(), SceneStringNames::get_singleton()->Master);
PhysicsDirectSpaceState2D *space_state = PhysicsServer2D::get_singleton()->space_get_direct_state(world_2d->get_space());
ERR_FAIL_COND_V(space_state == nullptr, SceneStringNames::get_singleton()->Master);
ERR_FAIL_NULL_V(space_state, SceneStringNames::get_singleton()->Master);
PhysicsDirectSpaceState2D::ShapeResult sr[MAX_INTERSECT_AREAS];
PhysicsDirectSpaceState2D::PointParameters point_params;

View file

@ -560,7 +560,7 @@ Vector2 NavigationAgent2D::get_next_path_position() {
const Vector<Vector2> &navigation_path = navigation_result->get_path();
if (navigation_path.size() == 0) {
ERR_FAIL_COND_V_MSG(agent_parent == nullptr, Vector2(), "The agent has no parent.");
ERR_FAIL_NULL_V_MSG(agent_parent, Vector2(), "The agent has no parent.");
return agent_parent->get_global_position();
} else {
return navigation_path[navigation_path_index];
@ -568,7 +568,7 @@ Vector2 NavigationAgent2D::get_next_path_position() {
}
real_t NavigationAgent2D::distance_to_target() const {
ERR_FAIL_COND_V_MSG(agent_parent == nullptr, 0.0, "The agent has no parent.");
ERR_FAIL_NULL_V_MSG(agent_parent, 0.0, "The agent has no parent.");
return agent_parent->get_global_position().distance_to(target_position);
}

View file

@ -71,7 +71,7 @@ void PhysicalBone2D::_position_at_bone2d() {
// Reset to Bone2D position
if (parent_skeleton) {
Bone2D *bone_to_use = parent_skeleton->get_bone(bone2d_index);
ERR_FAIL_COND_MSG(bone_to_use == nullptr, "It's not possible to position the bone with ID: " + itos(bone2d_index));
ERR_FAIL_NULL_MSG(bone_to_use, "It's not possible to position the bone with ID: " + itos(bone2d_index) + ".");
set_global_transform(bone_to_use->get_global_transform());
}
}

View file

@ -602,7 +602,7 @@ Vector3 NavigationAgent3D::get_next_path_position() {
const Vector<Vector3> &navigation_path = navigation_result->get_path();
if (navigation_path.size() == 0) {
ERR_FAIL_COND_V_MSG(agent_parent == nullptr, Vector3(), "The agent has no parent.");
ERR_FAIL_NULL_V_MSG(agent_parent, Vector3(), "The agent has no parent.");
return agent_parent->get_global_position();
} else {
return navigation_path[navigation_path_index] - Vector3(0, path_height_offset, 0);
@ -610,7 +610,7 @@ Vector3 NavigationAgent3D::get_next_path_position() {
}
real_t NavigationAgent3D::distance_to_target() const {
ERR_FAIL_COND_V_MSG(agent_parent == nullptr, 0.0, "The agent has no parent.");
ERR_FAIL_NULL_V_MSG(agent_parent, 0.0, "The agent has no parent.");
return agent_parent->get_global_position().distance_to(target_position);
}

View file

@ -1231,7 +1231,7 @@ void AnimatedSprite3D::play(const StringName &p_name, float p_custom_scale, bool
name = animation;
}
ERR_FAIL_COND_MSG(frames == nullptr, vformat("There is no animation with name '%s'.", name));
ERR_FAIL_NULL_MSG(frames, vformat("There is no animation with name '%s'.", name));
ERR_FAIL_COND_MSG(!frames->get_animation_names().has(name), vformat("There is no animation with name '%s'.", name));
if (frames->get_frame_count(name) == 0) {

View file

@ -1100,7 +1100,7 @@ bool AnimationNodeStateMachinePlayback::_check_advance_condition(const Ref<Anima
if (transition->expression.is_valid()) {
AnimationTree *tree_base = state_machine->get_animation_tree();
ERR_FAIL_COND_V(tree_base == nullptr, false);
ERR_FAIL_NULL_V(tree_base, false);
NodePath advance_expression_base_node_path = tree_base->get_advance_expression_base_node();
Node *expression_base = tree_base->get_node_or_null(advance_expression_base_node_path);

View file

@ -33,7 +33,7 @@
#include "scene/gui/graph_edit.h"
void GraphEditArranger::arrange_nodes() {
ERR_FAIL_COND(!graph_edit);
ERR_FAIL_NULL(graph_edit);
if (!arranging_graph) {
arranging_graph = true;

View file

@ -216,7 +216,7 @@ String RichTextLabel::_letters(int p_num, bool p_capitalize) const {
}
void RichTextLabel::_update_line_font(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size) {
ERR_FAIL_COND(p_frame == nullptr);
ERR_FAIL_NULL(p_frame);
ERR_FAIL_COND(p_line < 0 || p_line >= (int)p_frame->lines.size());
Line &l = p_frame->lines[p_line];
@ -267,7 +267,7 @@ void RichTextLabel::_update_line_font(ItemFrame *p_frame, int p_line, const Ref<
}
float RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size, int p_width, float p_h) {
ERR_FAIL_COND_V(p_frame == nullptr, p_h);
ERR_FAIL_NULL_V(p_frame, p_h);
ERR_FAIL_COND_V(p_line < 0 || p_line >= (int)p_frame->lines.size(), p_h);
Line &l = p_frame->lines[p_line];
@ -448,7 +448,7 @@ float RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font
}
float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size, int p_width, float p_h, int *r_char_offset) {
ERR_FAIL_COND_V(p_frame == nullptr, p_h);
ERR_FAIL_NULL_V(p_frame, p_h);
ERR_FAIL_COND_V(p_line < 0 || p_line >= (int)p_frame->lines.size(), p_h);
Line &l = p_frame->lines[p_line];
@ -748,7 +748,7 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
}
int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_ofs, int p_width, const Color &p_base_color, int p_outline_size, const Color &p_outline_color, const Color &p_font_shadow_color, int p_shadow_outline_size, const Point2 &p_shadow_ofs, int &r_processed_glyphs) {
ERR_FAIL_COND_V(p_frame == nullptr, 0);
ERR_FAIL_NULL_V(p_frame, 0);
ERR_FAIL_COND_V(p_line < 0 || p_line >= (int)p_frame->lines.size(), 0);
Vector2 off;
@ -5025,7 +5025,7 @@ bool RichTextLabel::_search_table(ItemTable *p_table, List<Item *>::Element *p_f
}
bool RichTextLabel::_search_line(ItemFrame *p_frame, int p_line, const String &p_string, int p_char_idx, bool p_reverse_search) {
ERR_FAIL_COND_V(p_frame == nullptr, false);
ERR_FAIL_NULL_V(p_frame, false);
ERR_FAIL_COND_V(p_line < 0 || p_line >= (int)p_frame->lines.size(), false);
Line &l = p_frame->lines[p_line];
@ -5110,14 +5110,14 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
while (parent_element->get() != selection.from_frame) {
parent_element = p_search_previous ? parent_element->prev() : parent_element->next();
ERR_FAIL_COND_V(parent_element == nullptr, false);
ERR_FAIL_NULL_V(parent_element, false);
}
// Search remainder of table
if (!(p_search_previous && parent_element == parent_table->subitems.front()) &&
parent_element != parent_table->subitems.back()) {
parent_element = p_search_previous ? parent_element->prev() : parent_element->next(); // Don't want to search current item
ERR_FAIL_COND_V(parent_element == nullptr, false);
ERR_FAIL_NULL_V(parent_element, false);
// Search for next element
if (_search_table(parent_table, parent_element, p_string, p_search_previous)) {
@ -5166,7 +5166,7 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
String RichTextLabel::_get_line_text(ItemFrame *p_frame, int p_line, Selection p_selection) const {
String txt;
ERR_FAIL_COND_V(p_frame == nullptr, txt);
ERR_FAIL_NULL_V(p_frame, txt);
ERR_FAIL_COND_V(p_line < 0 || p_line >= (int)p_frame->lines.size(), txt);
Line &l = p_frame->lines[p_line];

View file

@ -351,7 +351,7 @@ void ScrollContainer::_notification(int p_what) {
case NOTIFICATION_READY: {
Viewport *viewport = get_viewport();
ERR_FAIL_COND(!viewport);
ERR_FAIL_NULL(viewport);
viewport->connect("gui_focus_changed", callable_mp(this, &ScrollContainer::_gui_focus_changed));
_reposition_children();
} break;

View file

@ -303,7 +303,7 @@ void CanvasItem::_notification(int p_what) {
parent = parent->get_parent();
}
ERR_FAIL_COND(!viewport);
ERR_FAIL_NULL(viewport);
window = Object::cast_to<Window>(viewport);
if (window) {

View file

@ -1279,7 +1279,7 @@ SurfaceTool::CustomFormat SurfaceTool::get_custom_format(int p_channel_index) co
return last_custom_format[p_channel_index];
}
void SurfaceTool::optimize_indices_for_cache() {
ERR_FAIL_COND(optimize_vertex_cache_func == nullptr);
ERR_FAIL_NULL(optimize_vertex_cache_func);
ERR_FAIL_COND(index_array.size() == 0);
ERR_FAIL_COND(primitive != Mesh::PRIMITIVE_TRIANGLES);
ERR_FAIL_COND(index_array.size() % 3 != 0);
@ -1308,7 +1308,7 @@ Vector<int> SurfaceTool::generate_lod(float p_threshold, int p_target_index_coun
Vector<int> lod;
ERR_FAIL_COND_V(simplify_func == nullptr, lod);
ERR_FAIL_NULL_V(simplify_func, lod);
ERR_FAIL_COND_V(p_target_index_count < 0, lod);
ERR_FAIL_COND_V(vertex_array.size() == 0, lod);
ERR_FAIL_COND_V(index_array.size() == 0, lod);

View file

@ -5500,13 +5500,13 @@ int TileData::get_terrain_peering_bit(TileSet::CellNeighbor p_peering_bit) const
}
bool TileData::is_valid_terrain_peering_bit(TileSet::CellNeighbor p_peering_bit) const {
ERR_FAIL_COND_V(!tile_set, false);
ERR_FAIL_NULL_V(tile_set, false);
return tile_set->is_valid_terrain_peering_bit(terrain_set, p_peering_bit);
}
TileSet::TerrainsPattern TileData::get_terrains_pattern() const {
ERR_FAIL_COND_V(!tile_set, TileSet::TerrainsPattern());
ERR_FAIL_NULL_V(tile_set, TileSet::TerrainsPattern());
TileSet::TerrainsPattern output(tile_set, terrain_set);
output.set_terrain(terrain);
@ -5542,14 +5542,14 @@ float TileData::get_probability() const {
// Custom data
void TileData::set_custom_data(String p_layer_name, Variant p_value) {
ERR_FAIL_COND(!tile_set);
ERR_FAIL_NULL(tile_set);
int p_layer_id = tile_set->get_custom_data_layer_by_name(p_layer_name);
ERR_FAIL_COND_MSG(p_layer_id < 0, vformat("TileSet has no layer with name: %s", p_layer_name));
set_custom_data_by_layer_id(p_layer_id, p_value);
}
Variant TileData::get_custom_data(String p_layer_name) const {
ERR_FAIL_COND_V(!tile_set, Variant());
ERR_FAIL_NULL_V(tile_set, Variant());
int p_layer_id = tile_set->get_custom_data_layer_by_name(p_layer_name);
ERR_FAIL_COND_V_MSG(p_layer_id < 0, Variant(), vformat("TileSet has no layer with name: %s", p_layer_name));
return get_custom_data_by_layer_id(p_layer_id);

View file

@ -353,7 +353,7 @@ void ThemeDB::bind_class_external_item(const StringName &p_class_name, const Str
}
void ThemeDB::update_class_instance_items(Node *p_instance) {
ERR_FAIL_COND(!p_instance);
ERR_FAIL_NULL(p_instance);
// Use the hierarchy to initialize all inherited theme caches. Setters carry the necessary
// context and will set the values appropriately.