diff --git a/core/crypto/crypto_core.cpp b/core/crypto/crypto_core.cpp index 3ca2ec282f5..17b34c08e2b 100644 --- a/core/crypto/crypto_core.cpp +++ b/core/crypto/crypto_core.cpp @@ -73,7 +73,7 @@ Error CryptoCore::RandomGenerator::init() { } Error CryptoCore::RandomGenerator::get_random_bytes(uint8_t *r_buffer, size_t p_bytes) { - ERR_FAIL_COND_V(!ctx, ERR_UNCONFIGURED); + ERR_FAIL_NULL_V(ctx, ERR_UNCONFIGURED); int ret = mbedtls_ctr_drbg_random((mbedtls_ctr_drbg_context *)ctx, r_buffer, p_bytes); ERR_FAIL_COND_V_MSG(ret, FAILED, " failed\n ! mbedtls_ctr_drbg_seed returned an error" + itos(ret)); return OK; diff --git a/core/crypto/hashing_context.cpp b/core/crypto/hashing_context.cpp index 35f491cd0c2..157a0c091b7 100644 --- a/core/crypto/hashing_context.cpp +++ b/core/crypto/hashing_context.cpp @@ -35,7 +35,7 @@ Error HashingContext::start(HashType p_type) { ERR_FAIL_COND_V(ctx != nullptr, ERR_ALREADY_IN_USE); _create_ctx(p_type); - ERR_FAIL_COND_V(ctx == nullptr, ERR_UNAVAILABLE); + ERR_FAIL_NULL_V(ctx, ERR_UNAVAILABLE); switch (type) { case HASH_MD5: return ((CryptoCore::MD5Context *)ctx)->start(); @@ -48,7 +48,7 @@ Error HashingContext::start(HashType p_type) { } Error HashingContext::update(PackedByteArray p_chunk) { - ERR_FAIL_COND_V(ctx == nullptr, ERR_UNCONFIGURED); + ERR_FAIL_NULL_V(ctx, ERR_UNCONFIGURED); size_t len = p_chunk.size(); ERR_FAIL_COND_V(len == 0, FAILED); const uint8_t *r = p_chunk.ptr(); @@ -64,7 +64,7 @@ Error HashingContext::update(PackedByteArray p_chunk) { } PackedByteArray HashingContext::finish() { - ERR_FAIL_COND_V(ctx == nullptr, PackedByteArray()); + ERR_FAIL_NULL_V(ctx, PackedByteArray()); PackedByteArray out; Error err = FAILED; switch (type) { diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index b4d6fa41746..a817ea871d4 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -415,7 +415,7 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { Array msg; msg.push_back(p_can_continue); msg.push_back(error_str); - ERR_FAIL_COND(!script_lang); + ERR_FAIL_NULL(script_lang); msg.push_back(script_lang->debug_get_stack_level_count() > 0); msg.push_back(Thread::get_caller_id() == Thread::get_main_id() ? String(RTR("Main Thread")) : itos(Thread::get_caller_id())); if (allow_focus_steal_fn) { @@ -485,7 +485,7 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { } else if (command == "get_stack_frame_vars") { ERR_FAIL_COND(data.size() != 1); - ERR_FAIL_COND(!script_lang); + ERR_FAIL_NULL(script_lang); int lv = data[0]; List members; diff --git a/core/extension/gdextension.cpp b/core/extension/gdextension.cpp index bd3f14c4309..96ad1570cd9 100644 --- a/core/extension/gdextension.cpp +++ b/core/extension/gdextension.cpp @@ -491,7 +491,7 @@ void GDExtension::register_interface_function(StringName p_function_name, GDExte GDExtensionInterfaceFunctionPtr GDExtension::get_interface_function(StringName p_function_name) { GDExtensionInterfaceFunctionPtr *function = gdextension_interface_functions.getptr(p_function_name); - ERR_FAIL_COND_V_MSG(function == nullptr, nullptr, "Attempt to get non-existent interface function: " + p_function_name); + ERR_FAIL_NULL_V_MSG(function, nullptr, "Attempt to get non-existent interface function: " + String(p_function_name) + "."); return *function; } @@ -525,7 +525,7 @@ Error GDExtension::open_library(const String &p_path, const String &p_entry_symb } void GDExtension::close_library() { - ERR_FAIL_COND(library == nullptr); + ERR_FAIL_NULL(library); OS::get_singleton()->close_dynamic_library(library); #if defined(TOOLS_ENABLED) && defined(WINDOWS_ENABLED) @@ -543,12 +543,12 @@ bool GDExtension::is_library_open() const { } GDExtension::InitializationLevel GDExtension::get_minimum_library_initialization_level() const { - ERR_FAIL_COND_V(library == nullptr, INITIALIZATION_LEVEL_CORE); + ERR_FAIL_NULL_V(library, INITIALIZATION_LEVEL_CORE); return InitializationLevel(initialization.minimum_initialization_level); } void GDExtension::initialize_library(InitializationLevel p_level) { - ERR_FAIL_COND(library == nullptr); + ERR_FAIL_NULL(library); ERR_FAIL_COND_MSG(p_level <= int32_t(level_initialized), vformat("Level '%d' must be higher than the current level '%d'", p_level, level_initialized)); level_initialized = int32_t(p_level); @@ -558,7 +558,7 @@ void GDExtension::initialize_library(InitializationLevel p_level) { initialization.initialize(initialization.userdata, GDExtensionInitializationLevel(p_level)); } void GDExtension::deinitialize_library(InitializationLevel p_level) { - ERR_FAIL_COND(library == nullptr); + ERR_FAIL_NULL(library); ERR_FAIL_COND(p_level > int32_t(level_initialized)); level_initialized = int32_t(p_level) - 1; diff --git a/core/extension/gdextension_interface.cpp b/core/extension/gdextension_interface.cpp index a09b1f491e4..f59ee291ed2 100644 --- a/core/extension/gdextension_interface.cpp +++ b/core/extension/gdextension_interface.cpp @@ -1097,7 +1097,7 @@ static GDExtensionScriptInstancePtr gdextension_placeholder_script_instance_crea static void gdextension_placeholder_script_instance_update(GDExtensionScriptInstancePtr p_placeholder, GDExtensionConstTypePtr p_properties, GDExtensionConstTypePtr p_values) { PlaceHolderScriptInstance *placeholder = dynamic_cast(reinterpret_cast(p_placeholder)); - ERR_FAIL_COND_MSG(!placeholder, "Unable to update placeholder, expected a PlaceHolderScriptInstance but received an invalid type."); + ERR_FAIL_NULL_MSG(placeholder, "Unable to update placeholder, expected a PlaceHolderScriptInstance but received an invalid type."); const Array &properties = *reinterpret_cast(p_properties); const Dictionary &values = *reinterpret_cast(p_values); @@ -1148,7 +1148,7 @@ static GDExtensionMethodBindPtr gdextension_classdb_get_method_bind(GDExtensionC ERR_PRINT("Method '" + classname + "." + methodname + "' has changed and no compatibility fallback has been provided. Please open an issue."); return nullptr; } - ERR_FAIL_COND_V(!mb, nullptr); + ERR_FAIL_NULL_V(mb, nullptr); if (mb->get_hash() != p_hash) { ERR_PRINT("Hash mismatch for method '" + classname + "." + methodname + "'."); return nullptr; diff --git a/core/io/compression.cpp b/core/io/compression.cpp index e36fb0afa4f..4e4627c40be 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -215,7 +215,7 @@ int Compression::decompress_dynamic(Vector *p_dst_vect, int p_max_dst_s #ifdef BROTLI_ENABLED BrotliDecoderResult ret; BrotliDecoderState *state = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr); - ERR_FAIL_COND_V(state == nullptr, Z_DATA_ERROR); + ERR_FAIL_NULL_V(state, Z_DATA_ERROR); // Setup the stream inputs. const uint8_t *next_in = p_src; diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index 14ec0be0927..0983920b94a 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -79,7 +79,7 @@ Error FileAccessMemory::open_custom(const uint8_t *p_data, uint64_t p_len) { } Error FileAccessMemory::open_internal(const String &p_path, int p_mode_flags) { - ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND); + ERR_FAIL_NULL_V(files, ERR_FILE_NOT_FOUND); String name = fix_path(p_path); //name = DirAccess::normalize_path(name); @@ -99,22 +99,22 @@ bool FileAccessMemory::is_open() const { } void FileAccessMemory::seek(uint64_t p_position) { - ERR_FAIL_COND(!data); + ERR_FAIL_NULL(data); pos = p_position; } void FileAccessMemory::seek_end(int64_t p_position) { - ERR_FAIL_COND(!data); + ERR_FAIL_NULL(data); pos = length + p_position; } uint64_t FileAccessMemory::get_position() const { - ERR_FAIL_COND_V(!data, 0); + ERR_FAIL_NULL_V(data, 0); return pos; } uint64_t FileAccessMemory::get_length() const { - ERR_FAIL_COND_V(!data, 0); + ERR_FAIL_NULL_V(data, 0); return length; } @@ -134,7 +134,7 @@ uint8_t FileAccessMemory::get_8() const { uint64_t FileAccessMemory::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(!data, -1); + ERR_FAIL_NULL_V(data, -1); uint64_t left = length - pos; uint64_t read = MIN(p_length, left); @@ -154,11 +154,11 @@ Error FileAccessMemory::get_error() const { } void FileAccessMemory::flush() { - ERR_FAIL_COND(!data); + ERR_FAIL_NULL(data); } void FileAccessMemory::store_8(uint8_t p_byte) { - ERR_FAIL_COND(!data); + ERR_FAIL_NULL(data); ERR_FAIL_COND(pos >= length); data[pos++] = p_byte; } diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index c7f1a73f971..d085c29728d 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -239,7 +239,7 @@ Error FileAccessZip::open_internal(const String &p_path, int p_mode_flags) { ERR_FAIL_COND_V(p_mode_flags & FileAccess::WRITE, FAILED); ZipArchive *arch = ZipArchive::get_singleton(); - ERR_FAIL_COND_V(!arch, FAILED); + ERR_FAIL_NULL_V(arch, FAILED); zfile = arch->get_file_handle(p_path); ERR_FAIL_COND_V(!zfile, FAILED); @@ -255,7 +255,7 @@ void FileAccessZip::_close() { } ZipArchive *arch = ZipArchive::get_singleton(); - ERR_FAIL_COND(!arch); + ERR_FAIL_NULL(arch); arch->close_handle(zfile); zfile = nullptr; } diff --git a/core/io/image.cpp b/core/io/image.cpp index ce2f47371af..204db687d88 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -2356,7 +2356,7 @@ void Image::initialize_data(const char **p_xpm) { } Color *colorptr = colormap.getptr(pixelstr); - ERR_FAIL_COND(!colorptr); + ERR_FAIL_NULL(colorptr); uint8_t pixel[4]; for (uint32_t i = 0; i < pixel_size; i++) { pixel[i] = CLAMP((*colorptr)[i] * 255, 0, 255); @@ -2646,23 +2646,23 @@ Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels switch (p_mode) { case COMPRESS_S3TC: { - ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE); + ERR_FAIL_NULL_V(_image_compress_bc_func, ERR_UNAVAILABLE); _image_compress_bc_func(this, p_channels); } break; case COMPRESS_ETC: { - ERR_FAIL_COND_V(!_image_compress_etc1_func, ERR_UNAVAILABLE); + ERR_FAIL_NULL_V(_image_compress_etc1_func, ERR_UNAVAILABLE); _image_compress_etc1_func(this); } break; case COMPRESS_ETC2: { - ERR_FAIL_COND_V(!_image_compress_etc2_func, ERR_UNAVAILABLE); + ERR_FAIL_NULL_V(_image_compress_etc2_func, ERR_UNAVAILABLE); _image_compress_etc2_func(this, p_channels); } break; case COMPRESS_BPTC: { - ERR_FAIL_COND_V(!_image_compress_bptc_func, ERR_UNAVAILABLE); + ERR_FAIL_NULL_V(_image_compress_bptc_func, ERR_UNAVAILABLE); _image_compress_bptc_func(this, p_channels); } break; case COMPRESS_ASTC: { - ERR_FAIL_COND_V(!_image_compress_astc_func, ERR_UNAVAILABLE); + ERR_FAIL_NULL_V(_image_compress_astc_func, ERR_UNAVAILABLE); _image_compress_astc_func(this, p_astc_format); } break; case COMPRESS_MAX: { @@ -3655,7 +3655,7 @@ void Image::bump_map_to_normal_map(float bump_scale) { const uint8_t *rp = data.ptr(); uint8_t *wp = result_image.ptrw(); - ERR_FAIL_COND(!rp); + ERR_FAIL_NULL(rp); unsigned char *write_ptr = wp; float *read_ptr = (float *)rp; @@ -3916,7 +3916,7 @@ Error Image::_load_from_buffer(const Vector &p_array, ImageMemLoadFunc int buffer_size = p_array.size(); ERR_FAIL_COND_V(buffer_size == 0, ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(!p_loader, ERR_INVALID_PARAMETER); + ERR_FAIL_NULL_V(p_loader, ERR_INVALID_PARAMETER); const uint8_t *r = p_array.ptr(); diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 772f700916c..254351897d5 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -333,7 +333,7 @@ IP *(*IP::_create)() = nullptr; IP *IP::create() { ERR_FAIL_COND_V_MSG(singleton, nullptr, "IP singleton already exist."); - ERR_FAIL_COND_V(!_create, nullptr); + ERR_FAIL_NULL_V(_create, nullptr); return _create(); } diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 6ca7b0f831c..bfef9ebeaf6 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -640,7 +640,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } else { Object *obj = ClassDB::instantiate(str); - ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE); + ERR_FAIL_NULL_V(obj, ERR_UNAVAILABLE); ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); @@ -1576,7 +1576,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo buf += len; } Variant *v = d.getptr(E); - ERR_FAIL_COND_V(!v, ERR_BUG); + ERR_FAIL_NULL_V(v, ERR_BUG); err = encode_variant(*v, buf, len, p_full_objects, p_depth + 1); ERR_FAIL_COND_V(err, err); ERR_FAIL_COND_V(len % 4, ERR_BUG); diff --git a/core/io/packed_data_container.cpp b/core/io/packed_data_container.cpp index ce4edb18fe1..11b0c697748 100644 --- a/core/io/packed_data_container.cpp +++ b/core/io/packed_data_container.cpp @@ -125,7 +125,7 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, b uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const { ERR_FAIL_COND_V(p_ofs + 4 > (uint32_t)data.size(), 0); const uint8_t *rd = data.ptr(); - ERR_FAIL_COND_V(!rd, 0); + ERR_FAIL_NULL_V(rd, 0); const uint8_t *r = &rd[p_ofs]; uint32_t type = decode_uint32(r); @@ -135,7 +135,7 @@ uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const { int PackedDataContainer::_size(uint32_t p_ofs) const { ERR_FAIL_COND_V(p_ofs + 4 > (uint32_t)data.size(), 0); const uint8_t *rd = data.ptr(); - ERR_FAIL_COND_V(!rd, 0); + ERR_FAIL_NULL_V(rd, 0); const uint8_t *r = &rd[p_ofs]; uint32_t type = decode_uint32(r); @@ -156,7 +156,7 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, b const uint8_t *rd = data.ptr(); if (!rd) { err = true; - ERR_FAIL_COND_V(!rd, Variant()); + ERR_FAIL_NULL_V(rd, Variant()); } const uint8_t *r = &rd[p_ofs]; uint32_t type = decode_uint32(r); diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index c1a38f0af80..f7915261af1 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -1114,7 +1114,7 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) { Object *obj = ClassDB::instantiate(ibt); - ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource loader, expected 'ResourceFormatLoader' inheritance, got: " + String(ibt) + "."); + ERR_FAIL_NULL_V_MSG(obj, false, "Cannot instance script as custom resource loader, expected 'ResourceFormatLoader' inheritance, got: " + String(ibt) + "."); Ref crl = Object::cast_to(obj); crl->set_script(s); diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 6e377847a81..564a54b913a 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -241,7 +241,7 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) { Object *obj = ClassDB::instantiate(ibt); - ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource saver, expected 'ResourceFormatSaver' inheritance, got: " + String(ibt) + "."); + ERR_FAIL_NULL_V_MSG(obj, false, "Cannot instance script as custom resource saver, expected 'ResourceFormatSaver' inheritance, got: " + String(ibt) + "."); Ref crl = Object::cast_to(obj); crl->set_script(s); diff --git a/core/io/stream_peer_gzip.cpp b/core/io/stream_peer_gzip.cpp index 74216f3cff3..4daa71a22ac 100644 --- a/core/io/stream_peer_gzip.cpp +++ b/core/io/stream_peer_gzip.cpp @@ -102,7 +102,7 @@ Error StreamPeerGZIP::_start(bool p_compress, bool p_is_deflate, int buffer_size } Error StreamPeerGZIP::_process(uint8_t *p_dst, int p_dst_size, const uint8_t *p_src, int p_src_size, int &r_consumed, int &r_out, bool p_close) { - ERR_FAIL_COND_V(!ctx, ERR_UNCONFIGURED); + ERR_FAIL_NULL_V(ctx, ERR_UNCONFIGURED); z_stream &strm = *(z_stream *)ctx; strm.avail_in = p_src_size; strm.avail_out = p_dst_size; @@ -132,7 +132,7 @@ Error StreamPeerGZIP::put_data(const uint8_t *p_data, int p_bytes) { } Error StreamPeerGZIP::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { - ERR_FAIL_COND_V(!ctx, ERR_UNCONFIGURED); + ERR_FAIL_NULL_V(ctx, ERR_UNCONFIGURED); ERR_FAIL_COND_V(p_bytes < 0, ERR_INVALID_PARAMETER); // Ensure we have enough space in temporary buffer. diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index 958734addf7..faf7d75172b 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -336,7 +336,7 @@ uint64_t XMLParser::get_node_offset() const { } Error XMLParser::seek(uint64_t p_pos) { - ERR_FAIL_COND_V(!data, ERR_FILE_EOF); + ERR_FAIL_NULL_V(data, ERR_FILE_EOF); ERR_FAIL_COND_V(p_pos >= length, ERR_FILE_EOF); P = data + p_pos; @@ -474,7 +474,7 @@ Error XMLParser::open_buffer(const Vector &p_buffer) { Error XMLParser::_open_buffer(const uint8_t *p_buffer, size_t p_size) { ERR_FAIL_COND_V(p_size == 0, ERR_INVALID_DATA); - ERR_FAIL_COND_V(!p_buffer, ERR_INVALID_DATA); + ERR_FAIL_NULL_V(p_buffer, ERR_INVALID_DATA); if (data_copy) { memdelete_arr(data_copy); diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp index a0e6bd62de8..a89c6253f16 100644 --- a/core/io/zip_io.cpp +++ b/core/io/zip_io.cpp @@ -74,7 +74,7 @@ int godot_unzip_locate_file(unzFile p_zip_file, String p_filepath, bool p_case_s void *zipio_open(voidpf opaque, const char *p_fname, int mode) { Ref *fa = reinterpret_cast *>(opaque); - ERR_FAIL_COND_V(fa == nullptr, nullptr); + ERR_FAIL_NULL_V(fa, nullptr); String fname; fname.parse_utf8(p_fname); @@ -100,7 +100,7 @@ void *zipio_open(voidpf opaque, const char *p_fname, int mode) { uLong zipio_read(voidpf opaque, voidpf stream, void *buf, uLong size) { Ref *fa = reinterpret_cast *>(opaque); - ERR_FAIL_COND_V(fa == nullptr, 0); + ERR_FAIL_NULL_V(fa, 0); ERR_FAIL_COND_V(fa->is_null(), 0); return (*fa)->get_buffer((uint8_t *)buf, size); @@ -108,7 +108,7 @@ uLong zipio_read(voidpf opaque, voidpf stream, void *buf, uLong size) { uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong size) { Ref *fa = reinterpret_cast *>(opaque); - ERR_FAIL_COND_V(fa == nullptr, 0); + ERR_FAIL_NULL_V(fa, 0); ERR_FAIL_COND_V(fa->is_null(), 0); (*fa)->store_buffer((uint8_t *)buf, size); @@ -117,7 +117,7 @@ uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong size) { long zipio_tell(voidpf opaque, voidpf stream) { Ref *fa = reinterpret_cast *>(opaque); - ERR_FAIL_COND_V(fa == nullptr, 0); + ERR_FAIL_NULL_V(fa, 0); ERR_FAIL_COND_V(fa->is_null(), 0); return (*fa)->get_position(); @@ -125,7 +125,7 @@ long zipio_tell(voidpf opaque, voidpf stream) { long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { Ref *fa = reinterpret_cast *>(opaque); - ERR_FAIL_COND_V(fa == nullptr, 0); + ERR_FAIL_NULL_V(fa, 0); ERR_FAIL_COND_V(fa->is_null(), 0); uint64_t pos = offset; @@ -146,7 +146,7 @@ long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { int zipio_close(voidpf opaque, voidpf stream) { Ref *fa = reinterpret_cast *>(opaque); - ERR_FAIL_COND_V(fa == nullptr, 0); + ERR_FAIL_NULL_V(fa, 0); ERR_FAIL_COND_V(fa->is_null(), 0); fa->unref(); @@ -155,7 +155,7 @@ int zipio_close(voidpf opaque, voidpf stream) { int zipio_testerror(voidpf opaque, voidpf stream) { Ref *fa = reinterpret_cast *>(opaque); - ERR_FAIL_COND_V(fa == nullptr, 1); + ERR_FAIL_NULL_V(fa, 1); ERR_FAIL_COND_V(fa->is_null(), 0); return (fa->is_valid() && (*fa)->get_error() != OK) ? 1 : 0; diff --git a/core/math/disjoint_set.h b/core/math/disjoint_set.h index 78ae77e72c3..2ece991fea5 100644 --- a/core/math/disjoint_set.h +++ b/core/math/disjoint_set.h @@ -134,7 +134,7 @@ void DisjointSet::get_representatives(Vector &out_representative template void DisjointSet::get_members(Vector &out_members, T representative) { typename MapT::Iterator rep_itr = elements.find(representative); - ERR_FAIL_COND(rep_itr == nullptr); + ERR_FAIL_NULL(rep_itr); Element *rep_element = rep_itr->value; ERR_FAIL_COND(rep_element->parent != rep_element); diff --git a/core/math/dynamic_bvh.h b/core/math/dynamic_bvh.h index 21b5340aaa6..dbc1cb31de5 100644 --- a/core/math/dynamic_bvh.h +++ b/core/math/dynamic_bvh.h @@ -190,7 +190,7 @@ private: _FORCE_INLINE_ bool is_internal() const { return (!is_leaf()); } _FORCE_INLINE_ int get_index_in_parent() const { - ERR_FAIL_COND_V(!parent, 0); + ERR_FAIL_NULL_V(parent, 0); return (parent->children[1] == this) ? 1 : 0; } void get_max_depth(int depth, int &maxdepth) { diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 9cefd3999d1..100cb8e6a20 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -144,7 +144,7 @@ StringName ClassDB::get_compatibility_remapped_class(const StringName &p_class) StringName ClassDB::_get_parent_class(const StringName &p_class) { ClassInfo *ti = classes.getptr(p_class); - ERR_FAIL_COND_V_MSG(!ti, StringName(), "Cannot get class '" + String(p_class) + "'."); + ERR_FAIL_NULL_V_MSG(ti, StringName(), "Cannot get class '" + String(p_class) + "'."); return ti->inherits; } @@ -159,7 +159,7 @@ ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) { ClassInfo *ti = classes.getptr(p_class); - ERR_FAIL_COND_V_MSG(!ti, API_NONE, "Cannot get class '" + String(p_class) + "'."); + ERR_FAIL_NULL_V_MSG(ti, API_NONE, "Cannot get class '" + String(p_class) + "'."); return ti->api; } @@ -180,7 +180,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) { for (const StringName &E : class_list) { ClassInfo *t = classes.getptr(E); - ERR_FAIL_COND_V_MSG(!t, 0, "Cannot get class '" + String(E) + "'."); + ERR_FAIL_NULL_V_MSG(t, 0, "Cannot get class '" + String(E) + "'."); if (t->api != p_api || !t->exposed) { continue; } @@ -278,7 +278,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) { for (const StringName &F : snames) { PropertySetGet *psg = t->property_setget.getptr(F); - ERR_FAIL_COND_V(!psg, 0); + ERR_FAIL_NULL_V(psg, 0); hash = hash_murmur3_one_64(F.hash(), hash); hash = hash_murmur3_one_64(psg->setter.hash(), hash); @@ -336,9 +336,9 @@ Object *ClassDB::instantiate(const StringName &p_class) { ti = classes.getptr(compat_classes[p_class]); } } - ERR_FAIL_COND_V_MSG(!ti, nullptr, "Cannot get class '" + String(p_class) + "'."); + ERR_FAIL_NULL_V_MSG(ti, nullptr, "Cannot get class '" + String(p_class) + "'."); ERR_FAIL_COND_V_MSG(ti->disabled, nullptr, "Class '" + String(p_class) + "' is disabled."); - ERR_FAIL_COND_V_MSG(!ti->creation_func, nullptr, "Class '" + String(p_class) + "' or its base class cannot be instantiated."); + ERR_FAIL_NULL_V_MSG(ti->creation_func, nullptr, "Class '" + String(p_class) + "' or its base class cannot be instantiated."); } #ifdef TOOLS_ENABLED if (ti->api == API_EDITOR && !Engine::get_singleton()->is_editor_hint()) { @@ -354,7 +354,7 @@ Object *ClassDB::instantiate(const StringName &p_class) { } void ClassDB::set_object_extension_instance(Object *p_object, const StringName &p_class, GDExtensionClassInstancePtr p_instance) { - ERR_FAIL_COND(!p_object); + ERR_FAIL_NULL(p_object); ClassInfo *ti; { OBJTYPE_RLOCK; @@ -364,9 +364,9 @@ void ClassDB::set_object_extension_instance(Object *p_object, const StringName & ti = classes.getptr(compat_classes[p_class]); } } - ERR_FAIL_COND_MSG(!ti, "Cannot get class '" + String(p_class) + "'."); + ERR_FAIL_NULL_MSG(ti, "Cannot get class '" + String(p_class) + "'."); ERR_FAIL_COND_MSG(ti->disabled, "Class '" + String(p_class) + "' is disabled."); - ERR_FAIL_COND_MSG(!ti->gdextension, "Class '" + String(p_class) + "' has no native extension."); + ERR_FAIL_NULL_MSG(ti->gdextension, "Class '" + String(p_class) + "' has no native extension."); } p_object->_extension = ti->gdextension; @@ -377,7 +377,7 @@ bool ClassDB::can_instantiate(const StringName &p_class) { OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); - ERR_FAIL_COND_V_MSG(!ti, false, "Cannot get class '" + String(p_class) + "'."); + ERR_FAIL_NULL_V_MSG(ti, false, "Cannot get class '" + String(p_class) + "'."); #ifdef TOOLS_ENABLED if (ti->api == API_EDITOR && !Engine::get_singleton()->is_editor_hint()) { return false; @@ -621,7 +621,7 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName ClassInfo *type = classes.getptr(p_class); - ERR_FAIL_COND(!type); + ERR_FAIL_NULL(type); if (type->constant_map.has(p_name)) { ERR_FAIL(); @@ -790,7 +790,7 @@ void ClassDB::set_method_error_return_values(const StringName &p_class, const St #ifdef DEBUG_METHODS_ENABLED ClassInfo *type = classes.getptr(p_class); - ERR_FAIL_COND(!type); + ERR_FAIL_NULL(type); type->method_error_values[p_method] = p_values; #endif @@ -800,7 +800,7 @@ Vector ClassDB::get_method_error_return_values(const StringName &p_class, #ifdef DEBUG_METHODS_ENABLED ClassInfo *type = classes.getptr(p_class); - ERR_FAIL_COND_V(!type, Vector()); + ERR_FAIL_NULL_V(type, Vector()); if (!type->method_error_values.has(p_method)) { return Vector(); @@ -853,7 +853,7 @@ void ClassDB::add_signal(const StringName &p_class, const MethodInfo &p_signal) OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); - ERR_FAIL_COND(!type); + ERR_FAIL_NULL(type); StringName sname = p_signal.name; @@ -872,7 +872,7 @@ void ClassDB::get_signal_list(const StringName &p_class, List *p_sig OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); - ERR_FAIL_COND(!type); + ERR_FAIL_NULL(type); ClassInfo *check = type; @@ -926,7 +926,7 @@ bool ClassDB::get_signal(const StringName &p_class, const StringName &p_signal, void ClassDB::add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix, int p_indent_depth) { OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); - ERR_FAIL_COND(!type); + ERR_FAIL_NULL(type); String prefix = p_prefix; if (p_indent_depth > 0) { @@ -939,7 +939,7 @@ void ClassDB::add_property_group(const StringName &p_class, const String &p_name void ClassDB::add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix, int p_indent_depth) { OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); - ERR_FAIL_COND(!type); + ERR_FAIL_NULL(type); String prefix = p_prefix; if (p_indent_depth > 0) { @@ -956,7 +956,7 @@ void ClassDB::add_property_array_count(const StringName &p_class, const String & void ClassDB::add_property_array(const StringName &p_class, const StringName &p_path, const String &p_array_element_prefix) { OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); - ERR_FAIL_COND(!type); + ERR_FAIL_NULL(type); type->property_list.push_back(PropertyInfo(Variant::NIL, p_path, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ARRAY, p_array_element_prefix)); } @@ -967,14 +967,14 @@ void ClassDB::add_property(const StringName &p_class, const PropertyInfo &p_pinf ClassInfo *type = classes.getptr(p_class); lock.read_unlock(); - ERR_FAIL_COND(!type); + ERR_FAIL_NULL(type); MethodBind *mb_set = nullptr; if (p_setter) { mb_set = get_method(p_class, p_setter); #ifdef DEBUG_METHODS_ENABLED - ERR_FAIL_COND_MSG(!mb_set, "Invalid setter '" + p_class + "::" + p_setter + "' for property '" + p_pinfo.name + "'."); + ERR_FAIL_NULL_MSG(mb_set, "Invalid setter '" + p_class + "::" + p_setter + "' for property '" + p_pinfo.name + "'."); int exp_args = 1 + (p_index >= 0 ? 1 : 0); ERR_FAIL_COND_MSG(mb_set->get_argument_count() != exp_args, "Invalid function for setter '" + p_class + "::" + p_setter + " for property '" + p_pinfo.name + "'."); @@ -986,7 +986,7 @@ void ClassDB::add_property(const StringName &p_class, const PropertyInfo &p_pinf mb_get = get_method(p_class, p_getter); #ifdef DEBUG_METHODS_ENABLED - ERR_FAIL_COND_MSG(!mb_get, "Invalid getter '" + p_class + "::" + p_getter + "' for property '" + p_pinfo.name + "'."); + ERR_FAIL_NULL_MSG(mb_get, "Invalid getter '" + p_class + "::" + p_getter + "' for property '" + p_pinfo.name + "'."); int exp_args = 0 + (p_index >= 0 ? 1 : 0); ERR_FAIL_COND_MSG(mb_get->get_argument_count() != exp_args, "Invalid function for getter '" + p_class + "::" + p_getter + "' for property: '" + p_pinfo.name + "'."); @@ -1031,7 +1031,7 @@ void ClassDB::add_linked_property(const StringName &p_class, const String &p_pro #ifdef TOOLS_ENABLED OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); - ERR_FAIL_COND(!type); + ERR_FAIL_NULL(type); ERR_FAIL_COND(!type->property_map.has(p_property)); ERR_FAIL_COND(!type->property_map.has(p_linked_property)); @@ -1306,7 +1306,7 @@ void ClassDB::set_method_flags(const StringName &p_class, const StringName &p_me OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; - ERR_FAIL_COND(!check); + ERR_FAIL_NULL(check); ERR_FAIL_COND(!check->method_map.has(p_method)); check->method_map[p_method]->set_hint_flags(p_flags); } @@ -1374,7 +1374,7 @@ MethodBind *ClassDB::_bind_vararg_method(MethodBind *p_bind, const StringName &p ClassInfo *type = classes.getptr(instance_type); if (!type) { memdelete(bind); - ERR_FAIL_COND_V(!type, nullptr); + ERR_FAIL_NULL_V(type, nullptr); } if (p_compatibility) { @@ -1406,7 +1406,7 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, bool p_ #endif OBJTYPE_WLOCK; - ERR_FAIL_COND_V(!p_bind, nullptr); + ERR_FAIL_NULL_V(p_bind, nullptr); p_bind->set_name(mdname); String instance_type = p_bind->get_instance_class(); @@ -1532,7 +1532,7 @@ bool ClassDB::is_class_enabled(const StringName &p_class) { } } - ERR_FAIL_COND_V_MSG(!ti, false, "Cannot get class '" + String(p_class) + "'."); + ERR_FAIL_NULL_V_MSG(ti, false, "Cannot get class '" + String(p_class) + "'."); return !ti->disabled; } @@ -1540,7 +1540,7 @@ bool ClassDB::is_class_exposed(const StringName &p_class) { OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); - ERR_FAIL_COND_V_MSG(!ti, false, "Cannot get class '" + String(p_class) + "'."); + ERR_FAIL_NULL_V_MSG(ti, false, "Cannot get class '" + String(p_class) + "'."); return ti->exposed; } @@ -1688,7 +1688,7 @@ void ClassDB::register_extension_class(ObjectGDExtension *p_extension) { void ClassDB::unregister_extension_class(const StringName &p_class) { ClassInfo *c = classes.getptr(p_class); - ERR_FAIL_COND_MSG(!c, "Class " + p_class + "does not exist"); + ERR_FAIL_NULL_MSG(c, "Class '" + String(p_class) + "' does not exist."); for (KeyValue &F : c->method_map) { memdelete(F.value); } diff --git a/core/object/class_db.h b/core/object/class_db.h index 9f86d3ab811..b112cddf38b 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -190,7 +190,7 @@ public: static_assert(TypesAreSame::value, "Class not declared properly, please use GDCLASS."); T::initialize_class(); ClassInfo *t = classes.getptr(T::get_class_static()); - ERR_FAIL_COND(!t); + ERR_FAIL_NULL(t); t->creation_func = &creator; t->exposed = true; t->is_virtual = p_virtual; @@ -205,7 +205,7 @@ public: static_assert(TypesAreSame::value, "Class not declared properly, please use GDCLASS."); T::initialize_class(); ClassInfo *t = classes.getptr(T::get_class_static()); - ERR_FAIL_COND(!t); + ERR_FAIL_NULL(t); t->exposed = true; t->class_ptr = T::get_class_ptr_static(); t->api = current_api; @@ -218,7 +218,7 @@ public: static_assert(TypesAreSame::value, "Class not declared properly, please use GDCLASS."); T::initialize_class(); ClassInfo *t = classes.getptr(T::get_class_static()); - ERR_FAIL_COND(!t); + ERR_FAIL_NULL(t); t->creation_func = &creator; t->exposed = false; t->is_virtual = false; @@ -241,7 +241,7 @@ public: static_assert(TypesAreSame::value, "Class not declared properly, please use GDCLASS."); T::initialize_class(); ClassInfo *t = classes.getptr(T::get_class_static()); - ERR_FAIL_COND(!t); + ERR_FAIL_NULL(t); t->creation_func = &_create_ptr_func; t->exposed = true; t->class_ptr = T::get_class_ptr_static(); @@ -347,7 +347,7 @@ public: GLOBAL_LOCK_FUNCTION; MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant); - ERR_FAIL_COND_V(!bind, nullptr); + ERR_FAIL_NULL_V(bind, nullptr); if constexpr (std::is_same::return_type, Object *>::value) { bind->set_return_type_is_raw_object_ptr(true); @@ -360,7 +360,7 @@ public: GLOBAL_LOCK_FUNCTION; MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant); - ERR_FAIL_COND_V(!bind, nullptr); + ERR_FAIL_NULL_V(bind, nullptr); if constexpr (std::is_same::return_type, Object *>::value) { bind->set_return_type_is_raw_object_ptr(true); diff --git a/core/object/object.cpp b/core/object/object.cpp index 50026fc266f..3fd7fe36e06 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -867,7 +867,7 @@ String Object::to_string() { void Object::set_script_and_instance(const Variant &p_script, ScriptInstance *p_instance) { //this function is not meant to be used in any of these ways ERR_FAIL_COND(p_script.is_null()); - ERR_FAIL_COND(!p_instance); + ERR_FAIL_NULL(p_instance); ERR_FAIL_COND(script_instance != nullptr || !script.is_null()); script = p_script; @@ -1300,7 +1300,7 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, ui ERR_FAIL_COND_V_MSG(p_callable.is_null(), ERR_INVALID_PARAMETER, "Cannot connect to '" + p_signal + "': the provided callable is null."); Object *target_object = p_callable.get_object(); - ERR_FAIL_COND_V_MSG(!target_object, ERR_INVALID_PARAMETER, "Cannot connect to '" + p_signal + "' to callable '" + p_callable + "': the callable object is null."); + ERR_FAIL_NULL_V_MSG(target_object, ERR_INVALID_PARAMETER, "Cannot connect to '" + p_signal + "' to callable '" + p_callable + "': the callable object is null."); SignalData *s = signal_map.getptr(p_signal); if (!s) { @@ -1385,7 +1385,7 @@ bool Object::_disconnect(const StringName &p_signal, const Callable &p_callable, ERR_FAIL_COND_V_MSG(p_callable.is_null(), false, "Cannot disconnect from '" + p_signal + "': the provided callable is null."); Object *target_object = p_callable.get_object(); - ERR_FAIL_COND_V_MSG(!target_object, false, "Cannot disconnect '" + p_signal + "' from callable '" + p_callable + "': the callable object is null."); + ERR_FAIL_NULL_V_MSG(target_object, false, "Cannot disconnect '" + p_signal + "' from callable '" + p_callable + "': the callable object is null."); SignalData *s = signal_map.getptr(p_signal); if (!s) { @@ -1393,7 +1393,7 @@ bool Object::_disconnect(const StringName &p_signal, const Callable &p_callable, (!script.is_null() && Ref