Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Modules] Replace ERR_FAIL_COND with ERR_FAIL_NULL where applicable #81760

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions drivers/vulkan/vulkan_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,7 @@ Error VulkanContext::_update_swap_chain(Window *window) {
err = fpGetPhysicalDeviceSurfacePresentModesKHR(gpu, window->surface, &presentModeCount, nullptr);
ERR_FAIL_COND_V(err, ERR_CANT_CREATE);
VkPresentModeKHR *presentModes = (VkPresentModeKHR *)malloc(presentModeCount * sizeof(VkPresentModeKHR));
ERR_FAIL_COND_V(!presentModes, ERR_CANT_CREATE);
ERR_FAIL_NULL_V(presentModes, ERR_CANT_CREATE);
err = fpGetPhysicalDeviceSurfacePresentModesKHR(gpu, window->surface, &presentModeCount, presentModes);
if (err) {
free(presentModes);
Expand Down Expand Up @@ -2062,7 +2062,7 @@ Error VulkanContext::_update_swap_chain(Window *window) {
}

VkImage *swapchainImages = (VkImage *)malloc(swapchainImageCount * sizeof(VkImage));
ERR_FAIL_COND_V(!swapchainImages, ERR_CANT_CREATE);
ERR_FAIL_NULL_V(swapchainImages, ERR_CANT_CREATE);
err = fpGetSwapchainImagesKHR(device, window->swapchain, &swapchainImageCount, swapchainImages);
if (err) {
free(swapchainImages);
Expand Down
2 changes: 1 addition & 1 deletion modules/basis_universal/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static Ref<Image> basis_universal_unpacker_ptr(const uint8_t *p_data, int p_size

const uint8_t *ptr = p_data;
int size = p_size;
ERR_FAIL_COND_V_MSG(p_data == nullptr, image, "Cannot unpack invalid basis universal data.");
ERR_FAIL_NULL_V_MSG(p_data, image, "Cannot unpack invalid basis universal data.");

basist::transcoder_texture_format format = basist::transcoder_texture_format::cTFTotalTextureFormats;
Image::Format imgfmt = Image::FORMAT_MAX;
Expand Down
4 changes: 2 additions & 2 deletions modules/csg/csg_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void CSGShape3D::_update_shape() {
root_mesh.unref(); //byebye root mesh

CSGBrush *n = _get_brush();
ERR_FAIL_COND_MSG(!n, "Cannot get CSGBrush.");
ERR_FAIL_NULL_MSG(n, "Cannot get CSGBrush.");

OAHashMap<Vector3, Vector3> vec_map;

Expand Down Expand Up @@ -458,7 +458,7 @@ void CSGShape3D::_update_shape() {
void CSGShape3D::_update_collision_faces() {
if (use_collision && is_root_shape() && root_collision_shape.is_valid()) {
CSGBrush *n = _get_brush();
ERR_FAIL_COND_MSG(!n, "Cannot get CSGBrush.");
ERR_FAIL_NULL_MSG(n, "Cannot get CSGBrush.");
Vector<Vector3> physics_faces;
physics_faces.resize(n->faces.size() * 3);
Vector3 *physicsw = physics_faces.ptrw();
Expand Down
44 changes: 22 additions & 22 deletions modules/enet/enet_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "core/variant/typed_array.h"

void ENetConnection::broadcast(enet_uint8 p_channel, ENetPacket *p_packet) {
ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_MSG(host, "The ENetConnection instance isn't currently active.");
ERR_FAIL_COND_MSG(p_channel >= host->channelLimit, vformat("Unable to send packet on channel %d, max channels: %d", p_channel, (int)host->channelLimit));
enet_host_broadcast(host, p_channel, p_packet);
}
Expand Down Expand Up @@ -71,7 +71,7 @@ Error ENetConnection::create_host(int p_max_peers, int p_max_channels, int p_in_
}

void ENetConnection::destroy() {
ERR_FAIL_COND_MSG(!host, "Host already destroyed");
ERR_FAIL_NULL_MSG(host, "Host already destroyed.");
for (List<Ref<ENetPacketPeer>>::Element *E = peers.front(); E; E = E->next()) {
E->get()->_on_disconnect();
}
Expand All @@ -82,7 +82,7 @@ void ENetConnection::destroy() {

Ref<ENetPacketPeer> ENetConnection::connect_to_host(const String &p_address, int p_port, int p_channels, int p_data) {
Ref<ENetPacketPeer> out;
ERR_FAIL_COND_V_MSG(!host, out, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_V_MSG(host, out, "The ENetConnection instance isn't currently active.");
ERR_FAIL_COND_V_MSG(peers.size(), out, "The ENetConnection is already connected to a peer.");
ERR_FAIL_COND_V_MSG(p_port < 1 || p_port > 65535, out, "The remote port number must be between 1 and 65535 (inclusive).");

Expand Down Expand Up @@ -160,7 +160,7 @@ ENetConnection::EventType ENetConnection::_parse_event(const ENetEvent &p_event,
}

ENetConnection::EventType ENetConnection::service(int p_timeout, Event &r_event) {
ERR_FAIL_COND_V_MSG(!host, EVENT_ERROR, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_V_MSG(host, EVENT_ERROR, "The ENetConnection instance isn't currently active.");
ERR_FAIL_COND_V(r_event.peer.is_valid(), EVENT_ERROR);

// Drop peers that have already been disconnected.
Expand All @@ -186,7 +186,7 @@ ENetConnection::EventType ENetConnection::service(int p_timeout, Event &r_event)
}

int ENetConnection::check_events(EventType &r_type, Event &r_event) {
ERR_FAIL_COND_V_MSG(!host, -1, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_V_MSG(host, -1, "The ENetConnection instance isn't currently active.");
ENetEvent event;
int ret = enet_host_check_events(host, &event);
if (ret < 0) {
Expand All @@ -198,32 +198,32 @@ int ENetConnection::check_events(EventType &r_type, Event &r_event) {
}

void ENetConnection::flush() {
ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_MSG(host, "The ENetConnection instance isn't currently active.");
enet_host_flush(host);
}

void ENetConnection::bandwidth_limit(int p_in_bandwidth, int p_out_bandwidth) {
ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_MSG(host, "The ENetConnection instance isn't currently active.");
enet_host_bandwidth_limit(host, p_in_bandwidth, p_out_bandwidth);
}

void ENetConnection::channel_limit(int p_max_channels) {
ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_MSG(host, "The ENetConnection instance isn't currently active.");
enet_host_channel_limit(host, p_max_channels);
}

void ENetConnection::bandwidth_throttle() {
ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_MSG(host, "The ENetConnection instance isn't currently active.");
enet_host_bandwidth_throttle(host);
}

void ENetConnection::compress(CompressionMode p_mode) {
ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_MSG(host, "The ENetConnection instance isn't currently active.");
Compressor::setup(host, p_mode);
}

double ENetConnection::pop_statistic(HostStatistic p_stat) {
ERR_FAIL_COND_V_MSG(!host, 0, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_V_MSG(host, 0, "The ENetConnection instance isn't currently active.");
uint32_t *ptr = nullptr;
switch (p_stat) {
case HOST_TOTAL_SENT_DATA:
Expand All @@ -239,19 +239,19 @@ double ENetConnection::pop_statistic(HostStatistic p_stat) {
ptr = &(host->totalReceivedPackets);
break;
}
ERR_FAIL_COND_V_MSG(ptr == nullptr, 0, "Invalid statistic: " + itos(p_stat));
ERR_FAIL_NULL_V_MSG(ptr, 0, "Invalid statistic: " + itos(p_stat) + ".");
uint32_t ret = *ptr;
*ptr = 0;
return ret;
}

int ENetConnection::get_max_channels() const {
ERR_FAIL_COND_V_MSG(!host, 0, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_V_MSG(host, 0, "The ENetConnection instance isn't currently active.");
return host->channelLimit;
}

int ENetConnection::get_local_port() const {
ERR_FAIL_COND_V_MSG(!host, 0, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_V_MSG(host, 0, "The ENetConnection instance isn't currently active.");
ERR_FAIL_COND_V_MSG(!(host->socket), 0, "The ENetConnection instance isn't currently bound");
ENetAddress address;
ERR_FAIL_COND_V_MSG(enet_socket_get_address(host->socket, &address), 0, "Unable to get socket address");
Expand All @@ -265,7 +265,7 @@ void ENetConnection::get_peers(List<Ref<ENetPacketPeer>> &r_peers) {
}

TypedArray<ENetPacketPeer> ENetConnection::_get_peers() {
ERR_FAIL_COND_V_MSG(!host, Array(), "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_V_MSG(host, Array(), "The ENetConnection instance isn't currently active.");
TypedArray<ENetPacketPeer> out;
for (const Ref<ENetPacketPeer> &I : peers) {
out.push_back(I);
Expand All @@ -275,7 +275,7 @@ TypedArray<ENetPacketPeer> ENetConnection::_get_peers() {

Error ENetConnection::dtls_server_setup(const Ref<TLSOptions> &p_options) {
#ifdef GODOT_ENET
ERR_FAIL_COND_V_MSG(!host, ERR_UNCONFIGURED, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_V_MSG(host, ERR_UNCONFIGURED, "The ENetConnection instance isn't currently active.");
ERR_FAIL_COND_V(p_options.is_null() || !p_options->is_server(), ERR_INVALID_PARAMETER);
return enet_host_dtls_server_setup(host, const_cast<TLSOptions *>(p_options.ptr())) ? FAILED : OK;
#else
Expand All @@ -285,7 +285,7 @@ Error ENetConnection::dtls_server_setup(const Ref<TLSOptions> &p_options) {

void ENetConnection::refuse_new_connections(bool p_refuse) {
#ifdef GODOT_ENET
ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_MSG(host, "The ENetConnection instance isn't currently active.");
enet_host_refuse_new_connections(host, p_refuse);
#else
ERR_FAIL_MSG("ENet DTLS support not available in this build.");
Expand All @@ -294,7 +294,7 @@ void ENetConnection::refuse_new_connections(bool p_refuse) {

Error ENetConnection::dtls_client_setup(const String &p_hostname, const Ref<TLSOptions> &p_options) {
#ifdef GODOT_ENET
ERR_FAIL_COND_V_MSG(!host, ERR_UNCONFIGURED, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_V_MSG(host, ERR_UNCONFIGURED, "The ENetConnection instance isn't currently active.");
ERR_FAIL_COND_V(p_options.is_null() || p_options->is_server(), ERR_INVALID_PARAMETER);
return enet_host_dtls_client_setup(host, p_hostname.utf8().get_data(), const_cast<TLSOptions *>(p_options.ptr())) ? FAILED : OK;
#else
Expand All @@ -315,7 +315,7 @@ Error ENetConnection::_create(ENetAddress *p_address, int p_max_peers, int p_max
p_in_bandwidth /* limit incoming bandwidth if > 0 */,
p_out_bandwidth /* limit outgoing bandwidth if > 0 */);

ERR_FAIL_COND_V_MSG(!host, ERR_CANT_CREATE, "Couldn't create an ENet host.");
ERR_FAIL_NULL_V_MSG(host, ERR_CANT_CREATE, "Couldn't create an ENet host.");
return OK;
}

Expand All @@ -335,15 +335,15 @@ Array ENetConnection::_service(int p_timeout) {
}

void ENetConnection::_broadcast(int p_channel, PackedByteArray p_packet, int p_flags) {
ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_MSG(host, "The ENetConnection instance isn't currently active.");
ERR_FAIL_COND_MSG(p_channel < 0 || p_channel > (int)host->channelLimit, "Invalid channel");
ERR_FAIL_COND_MSG(p_flags & ~ENetPacketPeer::FLAG_ALLOWED, "Invalid flags");
ENetPacket *pkt = enet_packet_create(p_packet.ptr(), p_packet.size(), p_flags);
broadcast(p_channel, pkt);
}

void ENetConnection::socket_send(const String &p_address, int p_port, const PackedByteArray &p_packet) {
ERR_FAIL_COND_MSG(!host, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_MSG(host, "The ENetConnection instance isn't currently active.");
ERR_FAIL_COND_MSG(!(host->socket), "The ENetConnection instance isn't currently bound");
ERR_FAIL_COND_MSG(p_port < 1 || p_port > 65535, "The remote port number must be between 1 and 65535 (inclusive).");

Expand Down Expand Up @@ -497,7 +497,7 @@ size_t ENetConnection::Compressor::enet_decompress(void *context, const enet_uin
}

void ENetConnection::Compressor::setup(ENetHost *p_host, CompressionMode p_mode) {
ERR_FAIL_COND(!p_host);
ERR_FAIL_NULL(p_host);
switch (p_mode) {
case COMPRESS_NONE: {
enet_host_compress(p_host, nullptr);
Expand Down
36 changes: 18 additions & 18 deletions modules/enet/enet_packet_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,51 @@
#include "enet_packet_peer.h"

void ENetPacketPeer::peer_disconnect(int p_data) {
ERR_FAIL_COND(!peer);
ERR_FAIL_NULL(peer);
enet_peer_disconnect(peer, p_data);
}

void ENetPacketPeer::peer_disconnect_later(int p_data) {
ERR_FAIL_COND(!peer);
ERR_FAIL_NULL(peer);
enet_peer_disconnect_later(peer, p_data);
}

void ENetPacketPeer::peer_disconnect_now(int p_data) {
ERR_FAIL_COND(!peer);
ERR_FAIL_NULL(peer);
enet_peer_disconnect_now(peer, p_data);
_on_disconnect();
}

void ENetPacketPeer::ping() {
ERR_FAIL_COND(!peer);
ERR_FAIL_NULL(peer);
enet_peer_ping(peer);
}

void ENetPacketPeer::ping_interval(int p_interval) {
ERR_FAIL_COND(!peer);
ERR_FAIL_NULL(peer);
enet_peer_ping_interval(peer, p_interval);
}

int ENetPacketPeer::send(uint8_t p_channel, ENetPacket *p_packet) {
ERR_FAIL_COND_V(peer == nullptr, -1);
ERR_FAIL_COND_V(p_packet == nullptr, -1);
ERR_FAIL_NULL_V(peer, -1);
ERR_FAIL_NULL_V(p_packet, -1);
ERR_FAIL_COND_V_MSG(p_channel >= peer->channelCount, -1, vformat("Unable to send packet on channel %d, max channels: %d", p_channel, (int)peer->channelCount));
return enet_peer_send(peer, p_channel, p_packet);
}

void ENetPacketPeer::reset() {
ERR_FAIL_COND_MSG(peer == nullptr, "Peer not connected");
ERR_FAIL_NULL_MSG(peer, "Peer not connected.");
enet_peer_reset(peer);
_on_disconnect();
}

void ENetPacketPeer::throttle_configure(int p_interval, int p_acceleration, int p_deceleration) {
ERR_FAIL_COND_MSG(peer == nullptr, "Peer not connected");
ERR_FAIL_NULL_MSG(peer, "Peer not connected.");
enet_peer_throttle_configure(peer, p_interval, p_acceleration, p_deceleration);
}

void ENetPacketPeer::set_timeout(int p_timeout, int p_timeout_min, int p_timeout_max) {
ERR_FAIL_COND_MSG(peer == nullptr, "Peer not connected");
ERR_FAIL_NULL_MSG(peer, "Peer not connected.");
ERR_FAIL_COND_MSG(p_timeout > p_timeout_min || p_timeout_min > p_timeout_max, "Timeout limit must be less than minimum timeout, which itself must be less than maximum timeout");
enet_peer_timeout(peer, p_timeout, p_timeout_min, p_timeout_max);
}
Expand All @@ -89,7 +89,7 @@ int ENetPacketPeer::get_available_packet_count() const {
}

Error ENetPacketPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
ERR_FAIL_COND_V(!peer, ERR_UNCONFIGURED);
ERR_FAIL_NULL_V(peer, ERR_UNCONFIGURED);
ERR_FAIL_COND_V(!packet_queue.size(), ERR_UNAVAILABLE);
if (last_packet) {
enet_packet_destroy(last_packet);
Expand All @@ -103,13 +103,13 @@ Error ENetPacketPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
}

Error ENetPacketPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
ERR_FAIL_COND_V(!peer, ERR_UNCONFIGURED);
ERR_FAIL_NULL_V(peer, ERR_UNCONFIGURED);
ENetPacket *packet = enet_packet_create(p_buffer, p_buffer_size, ENET_PACKET_FLAG_RELIABLE);
return send(0, packet) < 0 ? FAILED : OK;
}

IPAddress ENetPacketPeer::get_remote_address() const {
ERR_FAIL_COND_V(!peer, IPAddress());
ERR_FAIL_NULL_V(peer, IPAddress());
IPAddress out;
#ifdef GODOT_ENET
out.set_ipv6((uint8_t *)&(peer->address.host));
Expand All @@ -120,7 +120,7 @@ IPAddress ENetPacketPeer::get_remote_address() const {
}

int ENetPacketPeer::get_remote_port() const {
ERR_FAIL_COND_V(!peer, 0);
ERR_FAIL_NULL_V(peer, 0);
return peer->address.port;
}

Expand All @@ -129,7 +129,7 @@ bool ENetPacketPeer::is_active() const {
}

double ENetPacketPeer::get_statistic(PeerStatistic p_stat) {
ERR_FAIL_COND_V(!peer, 0);
ERR_FAIL_NULL_V(peer, 0);
switch (p_stat) {
case PEER_PACKET_LOSS:
return peer->packetLoss;
Expand Down Expand Up @@ -171,7 +171,7 @@ ENetPacketPeer::PeerState ENetPacketPeer::get_state() const {
}

int ENetPacketPeer::get_channels() const {
ERR_FAIL_COND_V_MSG(!peer, 0, "The ENetConnection instance isn't currently active.");
ERR_FAIL_NULL_V_MSG(peer, 0, "The ENetConnection instance isn't currently active.");
return peer->channelCount;
}

Expand All @@ -183,12 +183,12 @@ void ENetPacketPeer::_on_disconnect() {
}

void ENetPacketPeer::_queue_packet(ENetPacket *p_packet) {
ERR_FAIL_COND(!peer);
ERR_FAIL_NULL(peer);
packet_queue.push_back(p_packet);
}

Error ENetPacketPeer::_send(int p_channel, PackedByteArray p_packet, int p_flags) {
ERR_FAIL_COND_V_MSG(peer == nullptr, ERR_UNCONFIGURED, "Peer not connected");
ERR_FAIL_NULL_V_MSG(peer, ERR_UNCONFIGURED, "Peer not connected.");
ERR_FAIL_COND_V_MSG(p_channel < 0 || p_channel > (int)peer->channelCount, ERR_INVALID_PARAMETER, "Invalid channel");
ERR_FAIL_COND_V_MSG(p_flags & ~FLAG_ALLOWED, ERR_INVALID_PARAMETER, "Invalid flags");
ENetPacket *packet = enet_packet_create(p_packet.ptr(), p_packet.size(), p_flags);
Expand Down
4 changes: 2 additions & 2 deletions modules/gdscript/gdscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void GDScriptNativeClass::_bind_methods() {

Variant GDScriptNativeClass::_new() {
Object *o = instantiate();
ERR_FAIL_COND_V_MSG(!o, Variant(), "Class type: '" + String(name) + "' is not instantiable.");
ERR_FAIL_NULL_V_MSG(o, Variant(), "Class type: '" + String(name) + "' is not instantiable.");

RefCounted *rc = Object::cast_to<RefCounted>(o);
if (rc) {
Expand Down Expand Up @@ -215,7 +215,7 @@ Variant GDScript::_new(const Variant **p_args, int p_argcount, Callable::CallErr
} else {
owner = memnew(RefCounted); //by default, no base means use reference
}
ERR_FAIL_COND_V_MSG(!owner, Variant(), "Can't inherit from a virtual class.");
ERR_FAIL_NULL_V_MSG(owner, Variant(), "Can't inherit from a virtual class.");

RefCounted *r = Object::cast_to<RefCounted>(owner);
if (r) {
Expand Down
2 changes: 1 addition & 1 deletion modules/gdscript/gdscript_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ void GDScriptAnalyzer::resolve_class_body(GDScriptParser::ClassNode *p_class, bo
}

void GDScriptAnalyzer::resolve_node(GDScriptParser::Node *p_node, bool p_is_root) {
ERR_FAIL_COND_MSG(p_node == nullptr, "Trying to resolve type of a null node.");
ERR_FAIL_NULL_MSG(p_node, "Trying to resolve type of a null node.");

switch (p_node->type) {
case GDScriptParser::Node::NONE:
Expand Down
2 changes: 1 addition & 1 deletion modules/gdscript/gdscript_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ GDScriptAnalyzer *GDScriptParserRef::get_analyzer() {
}

Error GDScriptParserRef::raise_status(Status p_new_status) {
ERR_FAIL_COND_V(parser == nullptr, ERR_INVALID_DATA);
ERR_FAIL_NULL_V(parser, ERR_INVALID_DATA);

if (result != OK) {
return result;
Expand Down
2 changes: 1 addition & 1 deletion modules/gdscript/gdscript_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool GDScriptCompiler::_is_class_member_property(GDScript *owner, const StringNa
scr = scr->_base;
}

ERR_FAIL_COND_V(!nc, false);
ERR_FAIL_NULL_V(nc, false);

return ClassDB::has_property(nc->get_name(), p_name);
}
Expand Down
Loading