From f18aa00e8505439c1afc3dc0eb309429a88cf4de Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Thu, 28 Sep 2023 11:40:18 +0200 Subject: [PATCH] Replace `ERR_FAIL_COND` with `ERR_FAIL_NULL` where applicable --- core/extension/gdextension.cpp | 2 +- core/io/file_access_zip.cpp | 20 +++++++++---------- core/object/callable_method_pointer.h | 6 +++--- core/variant/variant.cpp | 2 +- drivers/gles3/rasterizer_canvas_gles3.cpp | 4 ++-- drivers/gles3/storage/material_storage.cpp | 2 +- drivers/unix/dir_access_unix.cpp | 6 +++--- drivers/vulkan/vulkan_context.cpp | 4 ++-- editor/animation_track_editor.cpp | 2 +- editor/export/export_template_manager.cpp | 2 +- editor/import/collada.cpp | 2 +- .../import/resource_importer_shader_file.cpp | 2 +- editor/plugins/script_text_editor.cpp | 2 +- editor/plugins/skeleton_3d_editor_plugin.cpp | 2 +- .../plugins/version_control_editor_plugin.cpp | 2 +- editor/project_manager.cpp | 2 +- editor/scene_tree_dock.cpp | 4 ++-- modules/enet/enet_connection.cpp | 4 ++-- modules/gdscript/gdscript_parser.cpp | 2 +- modules/mono/managed_callable.cpp | 2 +- modules/openxr/util.h | 4 ++-- modules/text_server_adv/text_server_adv.cpp | 2 +- modules/text_server_fb/text_server_fb.cpp | 2 +- platform/ios/display_server_ios.mm | 14 ++++++------- platform/linuxbsd/x11/display_server_x11.cpp | 2 +- platform/macos/display_server_macos.mm | 18 ++++++++--------- platform/macos/gl_manager_macos_legacy.mm | 4 ++-- platform/macos/os_macos.mm | 2 +- platform/web/javascript_bridge_singleton.cpp | 2 +- scene/animation/animation_player.cpp | 4 ++-- scene/gui/graph_element.cpp | 2 +- scene/main/node.h | 2 +- scene/main/viewport.cpp | 2 +- scene/main/window.cpp | 2 +- ...skeleton_modification_2d_physicalbones.cpp | 2 +- servers/physics_2d/godot_area_2d.cpp | 2 +- servers/physics_2d/godot_body_2d.cpp | 2 +- .../physics_2d/godot_physics_server_2d.cpp | 2 +- servers/physics_3d/godot_area_3d.cpp | 2 +- servers/physics_3d/godot_body_3d.cpp | 2 +- .../physics_3d/godot_physics_server_3d.cpp | 14 ++++++------- servers/physics_3d/godot_soft_body_3d.cpp | 2 +- .../storage_rd/material_storage.cpp | 2 +- servers/rendering/shader_language.cpp | 2 +- thirdparty/enet/godot.cpp | 2 +- 45 files changed, 85 insertions(+), 85 deletions(-) diff --git a/core/extension/gdextension.cpp b/core/extension/gdextension.cpp index a4d4b9161e1..2a287a1816f 100644 --- a/core/extension/gdextension.cpp +++ b/core/extension/gdextension.cpp @@ -776,7 +776,7 @@ void GDExtension::initialize_library(InitializationLevel p_level) { level_initialized = int32_t(p_level); - ERR_FAIL_COND(initialization.initialize == nullptr); + ERR_FAIL_NULL(initialization.initialize); initialization.initialize(initialization.userdata, GDExtensionInitializationLevel(p_level)); } diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index d085c29728d..dd453324122 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -110,7 +110,7 @@ static void godot_free(voidpf opaque, voidpf address) { } // extern "C" void ZipArchive::close_handle(unzFile p_file) const { - ERR_FAIL_COND_MSG(!p_file, "Cannot close a file if none is open."); + ERR_FAIL_NULL_MSG(p_file, "Cannot close a file if none is open."); unzCloseCurrentFile(p_file); unzClose(p_file); } @@ -136,7 +136,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const { io.free_mem = godot_free; unzFile pkg = unzOpen2(packages[file.package].filename.utf8().get_data(), &io); - ERR_FAIL_COND_V_MSG(!pkg, nullptr, "Cannot open file '" + packages[file.package].filename + "'."); + ERR_FAIL_NULL_V_MSG(pkg, nullptr, "Cannot open file '" + packages[file.package].filename + "'."); int unz_err = unzGoToFilePos(pkg, &file.file_pos); if (unz_err != UNZ_OK || unzOpenCurrentFile(pkg) != UNZ_OK) { unzClose(pkg); @@ -168,7 +168,7 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, uint6 io.zerror_file = godot_testerror; unzFile zfile = unzOpen2(p_path.utf8().get_data(), &io); - ERR_FAIL_COND_V(!zfile, false); + ERR_FAIL_NULL_V(zfile, false); unz_global_info64 gi; int err = unzGetGlobalInfo64(zfile, &gi); @@ -241,7 +241,7 @@ Error FileAccessZip::open_internal(const String &p_path, int p_mode_flags) { ZipArchive *arch = ZipArchive::get_singleton(); ERR_FAIL_NULL_V(arch, FAILED); zfile = arch->get_file_handle(p_path); - ERR_FAIL_COND_V(!zfile, FAILED); + ERR_FAIL_NULL_V(zfile, FAILED); int err = unzGetCurrentFileInfo64(zfile, &file_info, nullptr, 0, nullptr, 0, nullptr, 0); ERR_FAIL_COND_V(err != UNZ_OK, FAILED); @@ -265,28 +265,28 @@ bool FileAccessZip::is_open() const { } void FileAccessZip::seek(uint64_t p_position) { - ERR_FAIL_COND(!zfile); + ERR_FAIL_NULL(zfile); unzSeekCurrentFile(zfile, p_position); } void FileAccessZip::seek_end(int64_t p_position) { - ERR_FAIL_COND(!zfile); + ERR_FAIL_NULL(zfile); unzSeekCurrentFile(zfile, get_length() + p_position); } uint64_t FileAccessZip::get_position() const { - ERR_FAIL_COND_V(!zfile, 0); + ERR_FAIL_NULL_V(zfile, 0); return unztell(zfile); } uint64_t FileAccessZip::get_length() const { - ERR_FAIL_COND_V(!zfile, 0); + ERR_FAIL_NULL_V(zfile, 0); return file_info.uncompressed_size; } bool FileAccessZip::eof_reached() const { - ERR_FAIL_COND_V(!zfile, true); + ERR_FAIL_NULL_V(zfile, true); return at_eof; } @@ -299,7 +299,7 @@ uint8_t FileAccessZip::get_8() const { uint64_t FileAccessZip::get_buffer(uint8_t *p_dst, uint64_t p_length) const { ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); - ERR_FAIL_COND_V(!zfile, -1); + ERR_FAIL_NULL_V(zfile, -1); at_eof = unzeof(zfile); if (at_eof) { diff --git a/core/object/callable_method_pointer.h b/core/object/callable_method_pointer.h index 2dbb7e468e4..db78b982e4f 100644 --- a/core/object/callable_method_pointer.h +++ b/core/object/callable_method_pointer.h @@ -99,7 +99,7 @@ public: virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const { #ifdef DEBUG_ENABLED - ERR_FAIL_COND_MSG(ObjectDB::get_instance(ObjectID(data.object_id)) == nullptr, "Invalid Object id '" + uitos(data.object_id) + "', can't call method."); + ERR_FAIL_NULL_MSG(ObjectDB::get_instance(ObjectID(data.object_id)), "Invalid Object id '" + uitos(data.object_id) + "', can't call method."); #endif call_with_variant_args(data.instance, data.method, p_arguments, p_argcount, r_call_error); } @@ -154,7 +154,7 @@ public: virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const { #ifdef DEBUG_ENABLED - ERR_FAIL_COND_MSG(ObjectDB::get_instance(ObjectID(data.object_id)) == nullptr, "Invalid Object id '" + uitos(data.object_id) + "', can't call method."); + ERR_FAIL_NULL_MSG(ObjectDB::get_instance(ObjectID(data.object_id)), "Invalid Object id '" + uitos(data.object_id) + "', can't call method."); #endif call_with_variant_args_ret(data.instance, data.method, p_arguments, p_argcount, r_return_value, r_call_error); } @@ -209,7 +209,7 @@ public: virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override { #ifdef DEBUG_ENABLED - ERR_FAIL_COND_MSG(ObjectDB::get_instance(ObjectID(data.object_id)) == nullptr, "Invalid Object id '" + uitos(data.object_id) + "', can't call method."); + ERR_FAIL_NULL_MSG(ObjectDB::get_instance(ObjectID(data.object_id)), "Invalid Object id '" + uitos(data.object_id) + "', can't call method."); #endif call_with_variant_args_retc(data.instance, data.method, p_arguments, p_argcount, r_return_value, r_call_error); } diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index 63ea3274ce8..09fb34e7c14 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -2117,7 +2117,7 @@ Variant::operator ::RID() const { } else if (type == OBJECT && _get_obj().obj) { #ifdef DEBUG_ENABLED if (EngineDebugger::is_active()) { - ERR_FAIL_COND_V_MSG(ObjectDB::get_instance(_get_obj().id) == nullptr, ::RID(), "Invalid pointer (object was freed)."); + ERR_FAIL_NULL_V_MSG(ObjectDB::get_instance(_get_obj().id), ::RID(), "Invalid pointer (object was freed)."); } #endif Callable::CallError ce; diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index 7fce06c1333..7aea1a18506 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -1236,7 +1236,7 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend } void RasterizerCanvasGLES3::_render_batch(Light *p_lights, uint32_t p_index) { - ERR_FAIL_COND(!state.canvas_instance_batches[state.current_batch_index].command); + ERR_FAIL_NULL(state.canvas_instance_batches[state.current_batch_index].command); // Used by Polygon and Mesh. static const GLenum prim[5] = { GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP }; @@ -2157,7 +2157,7 @@ void RasterizerCanvasGLES3::_bind_canvas_texture(RID p_texture, RS::CanvasItemTe GLES3::Texture *t = texture_storage->get_texture(p_texture); if (t) { - ERR_FAIL_COND(!t->canvas_texture); + ERR_FAIL_NULL(t->canvas_texture); ct = t->canvas_texture; if (t->render_target) { t->render_target->used_in_frame = true; diff --git a/drivers/gles3/storage/material_storage.cpp b/drivers/gles3/storage/material_storage.cpp index 016f5543685..a2728f854b4 100644 --- a/drivers/gles3/storage/material_storage.cpp +++ b/drivers/gles3/storage/material_storage.cpp @@ -2396,7 +2396,7 @@ void MaterialStorage::material_set_shader(RID p_material, RID p_shader) { return; } - ERR_FAIL_COND(shader->data == nullptr); + ERR_FAIL_NULL(shader->data); material->data = material_data_request_func[shader->mode](shader->data); material->data->self = p_material; diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index a162f461036..095991e27b7 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -339,7 +339,7 @@ Error DirAccessUnix::change_dir(String p_dir) { // prev_dir is the directory we are changing out of String prev_dir; char real_current_dir_name[2048]; - ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == nullptr, ERR_BUG); + ERR_FAIL_NULL_V(getcwd(real_current_dir_name, 2048), ERR_BUG); if (prev_dir.parse_utf8(real_current_dir_name) != OK) { prev_dir = real_current_dir_name; //no utf8, maybe latin? } @@ -361,7 +361,7 @@ Error DirAccessUnix::change_dir(String p_dir) { String base = _get_root_path(); if (!base.is_empty() && !try_dir.begins_with(base)) { - ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == nullptr, ERR_BUG); + ERR_FAIL_NULL_V(getcwd(real_current_dir_name, 2048), ERR_BUG); String new_dir; new_dir.parse_utf8(real_current_dir_name); @@ -496,7 +496,7 @@ DirAccessUnix::DirAccessUnix() { // set current directory to an absolute path of the current directory char real_current_dir_name[2048]; - ERR_FAIL_COND(getcwd(real_current_dir_name, 2048) == nullptr); + ERR_FAIL_NULL(getcwd(real_current_dir_name, 2048)); if (current_dir.parse_utf8(real_current_dir_name) != OK) { current_dir = real_current_dir_name; } diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp index 5bf988afb2d..890fd7277fd 100644 --- a/drivers/vulkan/vulkan_context.cpp +++ b/drivers/vulkan/vulkan_context.cpp @@ -1487,7 +1487,7 @@ Error VulkanContext::_create_physical_device(VkSurfaceKHR p_surface) { #define GET_INSTANCE_PROC_ADDR(inst, entrypoint) \ { \ fp##entrypoint = (PFN_vk##entrypoint)vkGetInstanceProcAddr(inst, "vk" #entrypoint); \ - ERR_FAIL_COND_V_MSG(fp##entrypoint == nullptr, ERR_CANT_CREATE, \ + ERR_FAIL_NULL_V_MSG(fp##entrypoint, ERR_CANT_CREATE, \ "vkGetInstanceProcAddr failed to find vk" #entrypoint); \ } @@ -1689,7 +1689,7 @@ Error VulkanContext::_initialize_queues(VkSurfaceKHR p_surface) { if (!g_gdpa) \ g_gdpa = (PFN_vkGetDeviceProcAddr)vkGetInstanceProcAddr(inst, "vkGetDeviceProcAddr"); \ fp##entrypoint = (PFN_vk##entrypoint)g_gdpa(dev, "vk" #entrypoint); \ - ERR_FAIL_COND_V_MSG(fp##entrypoint == nullptr, ERR_CANT_CREATE, \ + ERR_FAIL_NULL_V_MSG(fp##entrypoint, ERR_CANT_CREATE, \ "vkGetDeviceProcAddr failed to find vk" #entrypoint); \ } diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 919e335d21d..b5747819a39 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -3903,7 +3903,7 @@ void AnimationTrackEditor::insert_value_key(const String &p_property, const Vari ERR_FAIL_NULL(root); ERR_FAIL_COND(history->get_path_size() == 0); Object *obj = ObjectDB::get_instance(history->get_path_object(0)); - ERR_FAIL_COND(!Object::cast_to(obj)); + ERR_FAIL_NULL(Object::cast_to(obj)); // Let's build a node path. Node *node = Object::cast_to(obj); diff --git a/editor/export/export_template_manager.cpp b/editor/export/export_template_manager.cpp index 3a034c8dcc9..26ed7c46fbd 100644 --- a/editor/export/export_template_manager.cpp +++ b/editor/export/export_template_manager.cpp @@ -686,7 +686,7 @@ Error ExportTemplateManager::install_android_template_from_file(const String &p_ zlib_filefunc_def io = zipio_create_io(&io_fa); unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io); - ERR_FAIL_COND_V_MSG(!pkg, ERR_CANT_OPEN, "Android sources not in ZIP format."); + ERR_FAIL_NULL_V_MSG(pkg, ERR_CANT_OPEN, "Android sources not in ZIP format."); int ret = unzGoToFirstFile(pkg); int total_files = 0; diff --git a/editor/import/collada.cpp b/editor/import/collada.cpp index d27b0aea409..be63973ea7e 100644 --- a/editor/import/collada.cpp +++ b/editor/import/collada.cpp @@ -2197,7 +2197,7 @@ bool Collada::_move_geometry_to_skeletons(VisualScene *p_vscene, Node *p_node, L ERR_FAIL_COND_V(!state.scene_map.has(nodeid), false); //weird, it should have it... NodeJoint *nj = dynamic_cast(state.scene_map[nodeid]); ERR_FAIL_NULL_V(nj, false); - ERR_FAIL_COND_V(!nj->owner, false); //weird, node should have a skeleton owner + ERR_FAIL_NULL_V(nj->owner, false); // Weird, node should have a skeleton owner. NodeSkeleton *sk = nj->owner; diff --git a/editor/import/resource_importer_shader_file.cpp b/editor/import/resource_importer_shader_file.cpp index 1275e5b85ae..bde2e3d0bfc 100644 --- a/editor/import/resource_importer_shader_file.cpp +++ b/editor/import/resource_importer_shader_file.cpp @@ -96,7 +96,7 @@ Error ResourceImporterShaderFile::import(const String &p_source_file, const Stri Error err; Ref file = FileAccess::open(p_source_file, FileAccess::READ, &err); ERR_FAIL_COND_V(err != OK, ERR_CANT_OPEN); - ERR_FAIL_COND_V(!file.operator->(), ERR_CANT_OPEN); + ERR_FAIL_COND_V(!file.is_valid(), ERR_CANT_OPEN); String file_txt = file->get_as_utf8_string(); Ref shader_file; diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 20c4127c1d3..3ba86aa65b6 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -779,7 +779,7 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref