summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-02-09 18:09:11 +0100
committerRémi Verschelde <rverschelde@gmail.com>2024-02-09 18:09:11 +0100
commitd00dc8facfc343037b29e2eb6e828251e788df24 (patch)
tree79e480aca28088bb93451e165ce429374d97e421 /modules
parentd87dd6e7797088b57f9636e07d57fc67e0471e24 (diff)
parent684752e75bdeb58727c2d9b0ff0265d7fcd47de0 (diff)
downloadredot-engine-d00dc8facfc343037b29e2eb6e828251e788df24.tar.gz
Merge pull request #87371 from AThousandShips/size_err_check
Replace error checks against `size` with `is_empty`
Diffstat (limited to 'modules')
-rw-r--r--modules/csg/csg_shape.cpp2
-rw-r--r--modules/enet/enet_multiplayer_peer.cpp8
-rw-r--r--modules/enet/enet_packet_peer.cpp2
-rw-r--r--modules/gdscript/gdscript_parser.cpp2
-rw-r--r--modules/gltf/gltf_document.cpp18
-rw-r--r--modules/lightmapper_rd/lightmapper_rd.cpp4
-rw-r--r--modules/minimp3/resource_importer_mp3.cpp2
-rw-r--r--modules/multiplayer/multiplayer_debugger.cpp6
-rw-r--r--modules/multiplayer/scene_multiplayer.cpp4
-rw-r--r--modules/multiplayer/scene_replication_interface.cpp2
-rw-r--r--modules/navigation/nav_mesh_generator_3d.cpp2
-rw-r--r--modules/openxr/openxr_api.cpp2
-rw-r--r--modules/upnp/upnp.cpp2
-rw-r--r--modules/websocket/remote_debugger_peer_websocket.cpp2
-rw-r--r--modules/websocket/websocket_multiplayer_peer.cpp4
15 files changed, 31 insertions, 31 deletions
diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp
index 1de76c60b5..604ad5e1e4 100644
--- a/modules/csg/csg_shape.cpp
+++ b/modules/csg/csg_shape.cpp
@@ -800,7 +800,7 @@ CSGBrush *CSGMesh3D::_build_brush() {
if (arrays.size() == 0) {
_make_dirty();
- ERR_FAIL_COND_V(arrays.size() == 0, memnew(CSGBrush));
+ ERR_FAIL_COND_V(arrays.is_empty(), memnew(CSGBrush));
}
Vector<Vector3> avertices = arrays[Mesh::ARRAY_VERTEX];
diff --git a/modules/enet/enet_multiplayer_peer.cpp b/modules/enet/enet_multiplayer_peer.cpp
index 63f12ea1c1..910c4ed242 100644
--- a/modules/enet/enet_multiplayer_peer.cpp
+++ b/modules/enet/enet_multiplayer_peer.cpp
@@ -40,20 +40,20 @@ void ENetMultiplayerPeer::set_target_peer(int p_peer) {
int ENetMultiplayerPeer::get_packet_peer() const {
ERR_FAIL_COND_V_MSG(!_is_active(), 1, "The multiplayer instance isn't currently active.");
- ERR_FAIL_COND_V(incoming_packets.size() == 0, 1);
+ ERR_FAIL_COND_V(incoming_packets.is_empty(), 1);
return incoming_packets.front()->get().from;
}
MultiplayerPeer::TransferMode ENetMultiplayerPeer::get_packet_mode() const {
ERR_FAIL_COND_V_MSG(!_is_active(), TRANSFER_MODE_RELIABLE, "The multiplayer instance isn't currently active.");
- ERR_FAIL_COND_V(incoming_packets.size() == 0, TRANSFER_MODE_RELIABLE);
+ ERR_FAIL_COND_V(incoming_packets.is_empty(), TRANSFER_MODE_RELIABLE);
return incoming_packets.front()->get().transfer_mode;
}
int ENetMultiplayerPeer::get_packet_channel() const {
ERR_FAIL_COND_V_MSG(!_is_active(), 1, "The multiplayer instance isn't currently active.");
- ERR_FAIL_COND_V(incoming_packets.size() == 0, 1);
+ ERR_FAIL_COND_V(incoming_packets.is_empty(), 1);
int ch = incoming_packets.front()->get().channel;
if (ch >= SYSCH_MAX) { // First 2 channels are reserved.
return ch - SYSCH_MAX + 1;
@@ -321,7 +321,7 @@ int ENetMultiplayerPeer::get_available_packet_count() const {
}
Error ENetMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
- ERR_FAIL_COND_V_MSG(incoming_packets.size() == 0, ERR_UNAVAILABLE, "No incoming packets available.");
+ ERR_FAIL_COND_V_MSG(incoming_packets.is_empty(), ERR_UNAVAILABLE, "No incoming packets available.");
_pop_current_packet();
diff --git a/modules/enet/enet_packet_peer.cpp b/modules/enet/enet_packet_peer.cpp
index f2bf5337ee..edb33fc96b 100644
--- a/modules/enet/enet_packet_peer.cpp
+++ b/modules/enet/enet_packet_peer.cpp
@@ -90,7 +90,7 @@ int ENetPacketPeer::get_available_packet_count() const {
Error ENetPacketPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
ERR_FAIL_NULL_V(peer, ERR_UNCONFIGURED);
- ERR_FAIL_COND_V(!packet_queue.size(), ERR_UNAVAILABLE);
+ ERR_FAIL_COND_V(packet_queue.is_empty(), ERR_UNAVAILABLE);
if (last_packet) {
enet_packet_destroy(last_packet);
last_packet = nullptr;
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index 3ba6e4d160..649bd735c6 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -510,7 +510,7 @@ void GDScriptParser::push_multiline(bool p_state) {
}
void GDScriptParser::pop_multiline() {
- ERR_FAIL_COND_MSG(multiline_stack.size() == 0, "Parser bug: trying to pop from multiline stack without available value.");
+ ERR_FAIL_COND_MSG(multiline_stack.is_empty(), "Parser bug: trying to pop from multiline stack without available value.");
multiline_stack.pop_back();
tokenizer->set_multiline_mode(multiline_stack.size() > 0 ? multiline_stack.back()->get() : false);
}
diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp
index 1f819b96ba..ff2f290e4f 100644
--- a/modules/gltf/gltf_document.cpp
+++ b/modules/gltf/gltf_document.cpp
@@ -250,7 +250,7 @@ Error GLTFDocument::_serialize_gltf_extensions(Ref<GLTFState> p_state) const {
}
Error GLTFDocument::_serialize_scenes(Ref<GLTFState> p_state) {
- ERR_FAIL_COND_V_MSG(p_state->root_nodes.size() == 0, ERR_INVALID_DATA, "GLTF export: The scene must have at least one root node.");
+ ERR_FAIL_COND_V_MSG(p_state->root_nodes.is_empty(), ERR_INVALID_DATA, "GLTF export: The scene must have at least one root node.");
// Godot only supports one scene per glTF file.
Array scenes;
Dictionary scene_dict;
@@ -806,7 +806,7 @@ Error GLTFDocument::_parse_buffers(Ref<GLTFState> p_state, const String &p_base_
uri = uri.uri_decode();
uri = p_base_path.path_join(uri).replace("\\", "/"); // Fix for Windows.
buffer_data = FileAccess::get_file_as_bytes(uri);
- ERR_FAIL_COND_V_MSG(buffer.size() == 0, ERR_PARSE_ERROR, "glTF: Couldn't load binary file as an array: " + uri);
+ ERR_FAIL_COND_V_MSG(buffer.is_empty(), ERR_PARSE_ERROR, "glTF: Couldn't load binary file as an array: " + uri);
}
ERR_FAIL_COND_V(!buffer.has("byteLength"), ERR_PARSE_ERROR);
@@ -1544,7 +1544,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_ints(Ref<GLTFState> p_state,
}
}
- ERR_FAIL_COND_V(attribs.size() == 0, -1);
+ ERR_FAIL_COND_V(attribs.is_empty(), -1);
Ref<GLTFAccessor> accessor;
accessor.instantiate();
@@ -1903,7 +1903,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_floats(Ref<GLTFState> p_stat
_calc_accessor_min_max(i, element_count, type_max, attribs, type_min);
}
- ERR_FAIL_COND_V(!attribs.size(), -1);
+ ERR_FAIL_COND_V(attribs.is_empty(), -1);
Ref<GLTFAccessor> accessor;
accessor.instantiate();
@@ -2221,7 +2221,7 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> p_state) {
Dictionary attributes;
{
Vector<Vector3> a = array[Mesh::ARRAY_VERTEX];
- ERR_FAIL_COND_V(!a.size(), ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(a.is_empty(), ERR_INVALID_DATA);
attributes["POSITION"] = _encode_accessor_as_vec3(p_state, a, true);
vertex_num = a.size();
}
@@ -2788,7 +2788,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> p_state) {
} else if (primitive == Mesh::PRIMITIVE_TRIANGLES) {
//generate indices because they need to be swapped for CW/CCW
const Vector<Vector3> &vertices = array[Mesh::ARRAY_VERTEX];
- ERR_FAIL_COND_V(vertices.size() == 0, ERR_PARSE_ERROR);
+ ERR_FAIL_COND_V(vertices.is_empty(), ERR_PARSE_ERROR);
Vector<int> indices;
const int vs = vertices.size();
indices.resize(vs);
@@ -2919,7 +2919,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> p_state) {
if (t.has("TANGENT")) {
const Vector<Vector3> tangents_v3 = _decode_accessor_as_vec3(p_state, t["TANGENT"], true);
const Vector<float> src_tangents = array[Mesh::ARRAY_TANGENT];
- ERR_FAIL_COND_V(src_tangents.size() == 0, ERR_PARSE_ERROR);
+ ERR_FAIL_COND_V(src_tangents.is_empty(), ERR_PARSE_ERROR);
Vector<float> tangents_v4;
@@ -4414,7 +4414,7 @@ Error GLTFDocument::_verify_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin) {
out_roots.sort();
- ERR_FAIL_COND_V(out_roots.size() == 0, FAILED);
+ ERR_FAIL_COND_V(out_roots.is_empty(), FAILED);
// Make sure the roots are the exact same (they better be)
ERR_FAIL_COND_V(out_roots.size() != p_skin->roots.size(), FAILED);
@@ -6104,7 +6104,7 @@ struct SceneFormatImporterGLTFInterpolate<Quaternion> {
template <class T>
T GLTFDocument::_interpolate_track(const Vector<real_t> &p_times, const Vector<T> &p_values, const float p_time, const GLTFAnimation::Interpolation p_interp) {
- ERR_FAIL_COND_V(!p_values.size(), T());
+ ERR_FAIL_COND_V(p_values.is_empty(), T());
if (p_times.size() != (p_values.size() / (p_interp == GLTFAnimation::INTERP_CUBIC_SPLINE ? 3 : 1))) {
ERR_PRINT_ONCE("The interpolated values are not corresponding to its times.");
return p_values[0];
diff --git a/modules/lightmapper_rd/lightmapper_rd.cpp b/modules/lightmapper_rd/lightmapper_rd.cpp
index 02b5aefc9f..9ee281ad99 100644
--- a/modules/lightmapper_rd/lightmapper_rd.cpp
+++ b/modules/lightmapper_rd/lightmapper_rd.cpp
@@ -49,7 +49,7 @@ void LightmapperRD::add_mesh(const MeshData &p_mesh) {
ERR_FAIL_COND(p_mesh.emission_on_uv2.is_null() || p_mesh.emission_on_uv2->is_empty());
ERR_FAIL_COND(p_mesh.albedo_on_uv2->get_width() != p_mesh.emission_on_uv2->get_width());
ERR_FAIL_COND(p_mesh.albedo_on_uv2->get_height() != p_mesh.emission_on_uv2->get_height());
- ERR_FAIL_COND(p_mesh.points.size() == 0);
+ ERR_FAIL_COND(p_mesh.points.is_empty());
MeshInstance mi;
mi.data = p_mesh;
mesh_instances.push_back(mi);
@@ -1986,7 +1986,7 @@ Variant LightmapperRD::get_bake_mesh_userdata(int p_index) const {
}
Rect2 LightmapperRD::get_bake_mesh_uv_scale(int p_index) const {
- ERR_FAIL_COND_V(bake_textures.size() == 0, Rect2());
+ ERR_FAIL_COND_V(bake_textures.is_empty(), Rect2());
Rect2 uv_ofs;
Vector2 atlas_size = Vector2(bake_textures[0]->get_width(), bake_textures[0]->get_height());
uv_ofs.position = Vector2(mesh_instances[p_index].offset) / atlas_size;
diff --git a/modules/minimp3/resource_importer_mp3.cpp b/modules/minimp3/resource_importer_mp3.cpp
index 33c926689a..e4b54ef050 100644
--- a/modules/minimp3/resource_importer_mp3.cpp
+++ b/modules/minimp3/resource_importer_mp3.cpp
@@ -110,7 +110,7 @@ Ref<AudioStreamMP3> ResourceImporterMP3::import_mp3(const String &p_path) {
mp3_stream.instantiate();
mp3_stream->set_data(data);
- ERR_FAIL_COND_V(!mp3_stream->get_data().size(), Ref<AudioStreamMP3>());
+ ERR_FAIL_COND_V(mp3_stream->get_data().is_empty(), Ref<AudioStreamMP3>());
return mp3_stream;
}
diff --git a/modules/multiplayer/multiplayer_debugger.cpp b/modules/multiplayer/multiplayer_debugger.cpp
index a4d2aed2d6..c816bd3b6b 100644
--- a/modules/multiplayer/multiplayer_debugger.cpp
+++ b/modules/multiplayer/multiplayer_debugger.cpp
@@ -89,7 +89,7 @@ Error MultiplayerDebugger::_capture(void *p_user, const String &p_msg, const Arr
// BandwidthProfiler
int MultiplayerDebugger::BandwidthProfiler::bandwidth_usage(const Vector<BandwidthFrame> &p_buffer, int p_pointer) {
- ERR_FAIL_COND_V(p_buffer.size() == 0, 0);
+ ERR_FAIL_COND_V(p_buffer.is_empty(), 0);
int total_bandwidth = 0;
uint64_t timestamp = OS::get_singleton()->get_ticks_msec();
@@ -174,7 +174,7 @@ Array MultiplayerDebugger::RPCFrame::serialize() {
}
bool MultiplayerDebugger::RPCFrame::deserialize(const Array &p_arr) {
- ERR_FAIL_COND_V(p_arr.size() < 1, false);
+ ERR_FAIL_COND_V(p_arr.is_empty(), false);
uint32_t size = p_arr[0];
ERR_FAIL_COND_V(size % 6, false);
ERR_FAIL_COND_V((uint32_t)p_arr.size() != size + 1, false);
@@ -279,7 +279,7 @@ Array MultiplayerDebugger::ReplicationFrame::serialize() {
}
bool MultiplayerDebugger::ReplicationFrame::deserialize(const Array &p_arr) {
- ERR_FAIL_COND_V(p_arr.size() < 1, false);
+ ERR_FAIL_COND_V(p_arr.is_empty(), false);
uint32_t size = p_arr[0];
ERR_FAIL_COND_V(size % 7, false);
ERR_FAIL_COND_V((uint32_t)p_arr.size() != size + 1, false);
diff --git a/modules/multiplayer/scene_multiplayer.cpp b/modules/multiplayer/scene_multiplayer.cpp
index 665b246bc5..5655467df7 100644
--- a/modules/multiplayer/scene_multiplayer.cpp
+++ b/modules/multiplayer/scene_multiplayer.cpp
@@ -440,7 +440,7 @@ void SceneMultiplayer::disconnect_peer(int p_id) {
}
Error SceneMultiplayer::send_bytes(Vector<uint8_t> p_data, int p_to, MultiplayerPeer::TransferMode p_mode, int p_channel) {
- ERR_FAIL_COND_V_MSG(p_data.size() < 1, ERR_INVALID_DATA, "Trying to send an empty raw packet.");
+ ERR_FAIL_COND_V_MSG(p_data.is_empty(), ERR_INVALID_DATA, "Trying to send an empty raw packet.");
ERR_FAIL_COND_V_MSG(!multiplayer_peer.is_valid(), ERR_UNCONFIGURED, "Trying to send a raw packet while no multiplayer peer is active.");
ERR_FAIL_COND_V_MSG(multiplayer_peer->get_connection_status() != MultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED, "Trying to send a raw packet via a multiplayer peer which is not connected.");
@@ -460,7 +460,7 @@ Error SceneMultiplayer::send_bytes(Vector<uint8_t> p_data, int p_to, Multiplayer
Error SceneMultiplayer::send_auth(int p_to, Vector<uint8_t> p_data) {
ERR_FAIL_COND_V(multiplayer_peer.is_null() || multiplayer_peer->get_connection_status() != MultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED);
ERR_FAIL_COND_V(!pending_peers.has(p_to), ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(p_data.is_empty(), ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V_MSG(pending_peers[p_to].local, ERR_FILE_CANT_WRITE, "The authentication session was previously marked as completed, no more authentication data can be sent.");
ERR_FAIL_COND_V_MSG(pending_peers[p_to].remote, ERR_FILE_CANT_WRITE, "The remote peer notified that the authentication session was completed, no more authentication data can be sent.");
diff --git a/modules/multiplayer/scene_replication_interface.cpp b/modules/multiplayer/scene_replication_interface.cpp
index 35ff62dd06..b61cf0bf1d 100644
--- a/modules/multiplayer/scene_replication_interface.cpp
+++ b/modules/multiplayer/scene_replication_interface.cpp
@@ -783,7 +783,7 @@ Error SceneReplicationInterface::on_delta_receive(int p_from, const uint8_t *p_b
ERR_CONTINUE_MSG(true, "Ignoring delta for non-authority or invalid synchronizer.");
}
List<NodePath> props = sync->get_delta_properties(indexes);
- ERR_FAIL_COND_V(props.size() == 0, ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(props.is_empty(), ERR_INVALID_DATA);
Vector<Variant> vars;
vars.resize(props.size());
int consumed = 0;
diff --git a/modules/navigation/nav_mesh_generator_3d.cpp b/modules/navigation/nav_mesh_generator_3d.cpp
index b93d1dbd52..95854f29e7 100644
--- a/modules/navigation/nav_mesh_generator_3d.cpp
+++ b/modules/navigation/nav_mesh_generator_3d.cpp
@@ -713,7 +713,7 @@ void NavMeshGenerator3D::generator_bake_from_source_geometry_data(Ref<Navigation
Vector<unsigned char> tri_areas;
tri_areas.resize(ntris);
- ERR_FAIL_COND(tri_areas.size() == 0);
+ ERR_FAIL_COND(tri_areas.is_empty());
memset(tri_areas.ptrw(), 0, ntris * sizeof(unsigned char));
rcMarkWalkableTriangles(&ctx, cfg.walkableSlopeAngle, verts, nverts, tris, ntris, tri_areas.ptrw());
diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp
index 80ddfe703f..36c3faaf75 100644
--- a/modules/openxr/openxr_api.cpp
+++ b/modules/openxr/openxr_api.cpp
@@ -2857,7 +2857,7 @@ bool OpenXRAPI::sync_action_sets(const Vector<RID> p_active_sets) {
}
}
- ERR_FAIL_COND_V(active_sets.size() == 0, false);
+ ERR_FAIL_COND_V(active_sets.is_empty(), false);
XrActionsSyncInfo sync_info = {
XR_TYPE_ACTIONS_SYNC_INFO, // type
diff --git a/modules/upnp/upnp.cpp b/modules/upnp/upnp.cpp
index aef4f394b2..2812f37eb2 100644
--- a/modules/upnp/upnp.cpp
+++ b/modules/upnp/upnp.cpp
@@ -265,7 +265,7 @@ void UPNP::clear_devices() {
}
Ref<UPNPDevice> UPNP::get_gateway() const {
- ERR_FAIL_COND_V_MSG(devices.size() < 1, nullptr, "Couldn't find any UPNPDevices.");
+ ERR_FAIL_COND_V_MSG(devices.is_empty(), nullptr, "Couldn't find any UPNPDevices.");
for (int i = 0; i < devices.size(); i++) {
Ref<UPNPDevice> dev = get_device(i);
diff --git a/modules/websocket/remote_debugger_peer_websocket.cpp b/modules/websocket/remote_debugger_peer_websocket.cpp
index 791b6d9ec9..dc6833e8c3 100644
--- a/modules/websocket/remote_debugger_peer_websocket.cpp
+++ b/modules/websocket/remote_debugger_peer_websocket.cpp
@@ -91,7 +91,7 @@ bool RemoteDebuggerPeerWebSocket::has_message() {
}
Array RemoteDebuggerPeerWebSocket::get_message() {
- ERR_FAIL_COND_V(in_queue.size() < 1, Array());
+ ERR_FAIL_COND_V(in_queue.is_empty(), Array());
Array msg = in_queue[0];
in_queue.pop_front();
return msg;
diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp
index 9e706dbeef..332cf93d36 100644
--- a/modules/websocket/websocket_multiplayer_peer.cpp
+++ b/modules/websocket/websocket_multiplayer_peer.cpp
@@ -124,7 +124,7 @@ Error WebSocketMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buff
current_packet.data = nullptr;
}
- ERR_FAIL_COND_V(incoming_packets.size() == 0, ERR_UNAVAILABLE);
+ ERR_FAIL_COND_V(incoming_packets.is_empty(), ERR_UNAVAILABLE);
current_packet = incoming_packets.front()->get();
incoming_packets.pop_front();
@@ -164,7 +164,7 @@ void WebSocketMultiplayerPeer::set_target_peer(int p_target_peer) {
}
int WebSocketMultiplayerPeer::get_packet_peer() const {
- ERR_FAIL_COND_V(incoming_packets.size() == 0, 1);
+ ERR_FAIL_COND_V(incoming_packets.is_empty(), 1);
return incoming_packets.front()->get().source;
}