Skip to content

Commit

Permalink
[Modules] Improve use of Ref.is_null/valid
Browse files Browse the repository at this point in the history
Use `is_null` over `!is_valid` and vice versa.
  • Loading branch information
AThousandShips committed Aug 25, 2024
1 parent bc2d0e9 commit d480379
Show file tree
Hide file tree
Showing 25 changed files with 78 additions and 78 deletions.
4 changes: 2 additions & 2 deletions modules/csg/csg_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ bool CSGShape3D::_is_debug_collision_shape_visible() {
}

void CSGShape3D::_update_debug_collision_shape() {
if (!use_collision || !is_root_shape() || !root_collision_shape.is_valid() || !_is_debug_collision_shape_visible()) {
if (!use_collision || !is_root_shape() || root_collision_shape.is_null() || !_is_debug_collision_shape_visible()) {
return;
}

Expand Down Expand Up @@ -813,7 +813,7 @@ CSGPrimitive3D::CSGPrimitive3D() {
/////////////////////

CSGBrush *CSGMesh3D::_build_brush() {
if (!mesh.is_valid()) {
if (mesh.is_null()) {
return memnew(CSGBrush);
}

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 @@ -717,7 +717,7 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type
String ext = path.get_extension();
if (ext == GDScriptLanguage::get_singleton()->get_extension()) {
Ref<GDScriptParserRef> ref = parser->get_depended_parser_for(path);
if (!ref.is_valid() || ref->raise_status(GDScriptParserRef::INHERITANCE_SOLVED) != OK) {
if (ref.is_null() || ref->raise_status(GDScriptParserRef::INHERITANCE_SOLVED) != OK) {
push_error(vformat(R"(Could not parse global class "%s" from "%s".)", first, ScriptServer::get_global_class_path(first)), p_type);
return bad_type;
}
Expand Down
6 changes: 3 additions & 3 deletions modules/gdscript/gdscript_utility_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ struct GDScriptUtilityFunctionsDefinitions {
}

Ref<Script> scr = ResourceLoader::load(d["@path"]);
if (!scr.is_valid()) {
if (scr.is_null()) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::OBJECT;
Expand All @@ -345,7 +345,7 @@ struct GDScriptUtilityFunctionsDefinitions {

Ref<GDScript> gdscr = scr;

if (!gdscr.is_valid()) {
if (gdscr.is_null()) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::OBJECT;
Expand All @@ -361,7 +361,7 @@ struct GDScriptUtilityFunctionsDefinitions {

for (int i = 0; i < sub.get_name_count(); i++) {
gdscr = gdscr->subclasses[sub.get_name(i)];
if (!gdscr.is_valid()) {
if (gdscr.is_null()) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::OBJECT;
Expand Down
4 changes: 2 additions & 2 deletions modules/gdscript/language_server/gdscript_workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S
}

Ref<GDScript> scr = current->get_script();
if (!scr.is_valid() || !GDScript::is_canonically_equal_paths(scr->get_path(), path)) {
if (scr.is_null() || !GDScript::is_canonically_equal_paths(scr->get_path(), path)) {
current = owner_scene_node;
}
}
Expand Down Expand Up @@ -701,7 +701,7 @@ const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocu
if (OK == GDScriptLanguage::get_singleton()->lookup_code(parser->get_text_for_lookup_symbol(pos, symbol_identifier, p_func_required), symbol_identifier, path, nullptr, ret)) {
if (ret.type == ScriptLanguage::LOOKUP_RESULT_SCRIPT_LOCATION) {
String target_script_path = path;
if (!ret.script.is_null()) {
if (ret.script.is_valid()) {
target_script_path = ret.script->get_path();
} else if (!ret.class_path.is_empty()) {
target_script_path = ret.class_path;
Expand Down
2 changes: 1 addition & 1 deletion modules/gltf/gltf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> p_state) {
v = instance_materials.get(surface_i);
}
Ref<Material> mat = v;
if (!mat.is_valid()) {
if (mat.is_null()) {
mat = import_mesh->get_surface_material(surface_i);
}
if (mat.is_valid()) {
Expand Down
8 changes: 4 additions & 4 deletions modules/gridmap/editor/grid_map_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void GridMapEditor::_update_cursor_transform() {
cursor_transform = node->get_global_transform() * cursor_transform;

if (selected_palette >= 0) {
if (node && !node->get_mesh_library().is_null()) {
if (node && node->get_mesh_library().is_valid()) {
cursor_transform *= node->get_mesh_library()->get_item_mesh_transform(selected_palette);
}
}
Expand Down Expand Up @@ -903,7 +903,7 @@ void GridMapEditor::update_palette() {
}

mesh_library_palette->add_item("");
if (!preview.is_null()) {
if (preview.is_valid()) {
mesh_library_palette->set_item_icon(item, preview);
mesh_library_palette->set_item_tooltip(item, name);
}
Expand Down Expand Up @@ -1143,9 +1143,9 @@ void GridMapEditor::_update_cursor_instance() {
cursor_instance = RID();

if (selected_palette >= 0) {
if (node && !node->get_mesh_library().is_null()) {
if (node && node->get_mesh_library().is_valid()) {
Ref<Mesh> mesh = node->get_mesh_library()->get_item_mesh(selected_palette);
if (!mesh.is_null() && mesh->get_rid().is_valid()) {
if (mesh.is_valid() && mesh->get_rid().is_valid()) {
cursor_instance = RenderingServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world_3d()->get_scenario());
RenderingServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform);
}
Expand Down
16 changes: 8 additions & 8 deletions modules/gridmap/grid_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ RID GridMap::get_navigation_map() const {
}

void GridMap::set_mesh_library(const Ref<MeshLibrary> &p_mesh_library) {
if (!mesh_library.is_null()) {
if (mesh_library.is_valid()) {
mesh_library->disconnect_changed(callable_mp(this, &GridMap::_recreate_octant_data));
}
mesh_library = p_mesh_library;
if (!mesh_library.is_null()) {
if (mesh_library.is_valid()) {
mesh_library->connect_changed(callable_mp(this, &GridMap::_recreate_octant_data));
}

Expand Down Expand Up @@ -596,7 +596,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
ERR_CONTINUE(!cell_map.has(E));
const Cell &c = cell_map[E];

if (!mesh_library.is_valid() || !mesh_library->has_item(c.item)) {
if (mesh_library.is_null() || !mesh_library->has_item(c.item)) {
continue;
}

Expand Down Expand Up @@ -625,7 +625,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
// add the item's shape at given xform to octant's static_body
for (int i = 0; i < shapes.size(); i++) {
// add the item's shape
if (!shapes[i].shape.is_valid()) {
if (shapes[i].shape.is_null()) {
continue;
}
PhysicsServer3D::get_singleton()->body_add_shape(g.static_body, shapes[i].shape->get_rid(), xform * shapes[i].local_transform);
Expand Down Expand Up @@ -801,7 +801,7 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) {
if (!g.navigation_debug_edge_connections_instance.is_valid()) {
g.navigation_debug_edge_connections_instance = RenderingServer::get_singleton()->instance_create();
}
if (!g.navigation_debug_edge_connections_mesh.is_valid()) {
if (g.navigation_debug_edge_connections_mesh.is_null()) {
g.navigation_debug_edge_connections_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
}

Expand Down Expand Up @@ -1224,7 +1224,7 @@ void GridMap::clear_baked_meshes() {
}

void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texel_size) {
if (!mesh_library.is_valid()) {
if (mesh_library.is_null()) {
return;
}

Expand All @@ -1240,7 +1240,7 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe
}

Ref<Mesh> mesh = mesh_library->get_item_mesh(item);
if (!mesh.is_valid()) {
if (mesh.is_null()) {
continue;
}

Expand Down Expand Up @@ -1386,7 +1386,7 @@ void GridMap::_update_octant_navigation_debug_edge_connections_mesh(const Octant
g.navigation_debug_edge_connections_instance = RenderingServer::get_singleton()->instance_create();
}

if (!g.navigation_debug_edge_connections_mesh.is_valid()) {
if (g.navigation_debug_edge_connections_mesh.is_null()) {
g.navigation_debug_edge_connections_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
}

Expand Down
2 changes: 1 addition & 1 deletion modules/interactive_music/audio_stream_interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ void AudioStreamPlaybackInteractive::start(double p_from_pos) {
if (current < 0 || current >= stream->clip_count) {
return; // No playback possible.
}
if (!states[current].playback.is_valid()) {
if (states[current].playback.is_null()) {
return; //no playback possible
}
active = true;
Expand Down
2 changes: 1 addition & 1 deletion modules/interactive_music/audio_stream_playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ int AudioStreamPlaybackPlaylist::mix(AudioFrame *p_buffer, float p_rate_scale, i
break;
}

if (!playback[play_order[play_index]].is_valid()) {
if (playback[play_order[play_index]].is_null()) {
todo = to_mix; // Weird error.
active = false;
break;
Expand Down
8 changes: 4 additions & 4 deletions modules/mbedtls/crypto_mbedtls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ Vector<uint8_t> CryptoMbedTLS::sign(HashingContext::HashType p_hash_type, const
ERR_FAIL_COND_V_MSG(type == MBEDTLS_MD_NONE, Vector<uint8_t>(), "Invalid hash type.");
ERR_FAIL_COND_V_MSG(p_hash.size() != size, Vector<uint8_t>(), "Invalid hash provided. Size must be " + itos(size));
Ref<CryptoKeyMbedTLS> key = static_cast<Ref<CryptoKeyMbedTLS>>(p_key);
ERR_FAIL_COND_V_MSG(!key.is_valid(), Vector<uint8_t>(), "Invalid key provided.");
ERR_FAIL_COND_V_MSG(key.is_null(), Vector<uint8_t>(), "Invalid key provided.");
ERR_FAIL_COND_V_MSG(key->is_public_only(), Vector<uint8_t>(), "Invalid key provided. Cannot sign with public_only keys.");
size_t sig_size = 0;
#if MBEDTLS_VERSION_MAJOR >= 3
Expand All @@ -510,13 +510,13 @@ bool CryptoMbedTLS::verify(HashingContext::HashType p_hash_type, const Vector<ui
ERR_FAIL_COND_V_MSG(type == MBEDTLS_MD_NONE, false, "Invalid hash type.");
ERR_FAIL_COND_V_MSG(p_hash.size() != size, false, "Invalid hash provided. Size must be " + itos(size));
Ref<CryptoKeyMbedTLS> key = static_cast<Ref<CryptoKeyMbedTLS>>(p_key);
ERR_FAIL_COND_V_MSG(!key.is_valid(), false, "Invalid key provided.");
ERR_FAIL_COND_V_MSG(key.is_null(), false, "Invalid key provided.");
return mbedtls_pk_verify(&(key->pkey), type, p_hash.ptr(), size, p_signature.ptr(), p_signature.size()) == 0;
}

Vector<uint8_t> CryptoMbedTLS::encrypt(Ref<CryptoKey> p_key, const Vector<uint8_t> &p_plaintext) {
Ref<CryptoKeyMbedTLS> key = static_cast<Ref<CryptoKeyMbedTLS>>(p_key);
ERR_FAIL_COND_V_MSG(!key.is_valid(), Vector<uint8_t>(), "Invalid key provided.");
ERR_FAIL_COND_V_MSG(key.is_null(), Vector<uint8_t>(), "Invalid key provided.");
uint8_t buf[1024];
size_t size;
Vector<uint8_t> out;
Expand All @@ -529,7 +529,7 @@ Vector<uint8_t> CryptoMbedTLS::encrypt(Ref<CryptoKey> p_key, const Vector<uint8_

Vector<uint8_t> CryptoMbedTLS::decrypt(Ref<CryptoKey> p_key, const Vector<uint8_t> &p_ciphertext) {
Ref<CryptoKeyMbedTLS> key = static_cast<Ref<CryptoKeyMbedTLS>>(p_key);
ERR_FAIL_COND_V_MSG(!key.is_valid(), Vector<uint8_t>(), "Invalid key provided.");
ERR_FAIL_COND_V_MSG(key.is_null(), Vector<uint8_t>(), "Invalid key provided.");
ERR_FAIL_COND_V_MSG(key->is_public_only(), Vector<uint8_t>(), "Invalid key provided. Cannot decrypt using a public_only key.");
uint8_t buf[2048];
size_t size;
Expand Down
2 changes: 1 addition & 1 deletion modules/mbedtls/dtls_server_mbedtls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Ref<PacketPeerDTLS> DTLSServerMbedTLS::take_connection(Ref<PacketPeerUDP> p_udp_
Ref<PacketPeerMbedDTLS> out;

ERR_FAIL_COND_V(tls_options.is_null(), out);
ERR_FAIL_COND_V(!p_udp_peer.is_valid(), out);
ERR_FAIL_COND_V(p_udp_peer.is_null(), out);

out.instantiate();
out->accept_peer(p_udp_peer, tls_options, cookies);
Expand Down
6 changes: 3 additions & 3 deletions modules/mbedtls/packet_peer_mbed_dtls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Error PacketPeerMbedDTLS::_do_handshake() {
}

Error PacketPeerMbedDTLS::connect_to_peer(Ref<PacketPeerUDP> p_base, const String &p_hostname, Ref<TLSOptions> p_options) {
ERR_FAIL_COND_V(!p_base.is_valid() || !p_base->is_socket_connected(), ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(p_base.is_null() || !p_base->is_socket_connected(), ERR_INVALID_PARAMETER);

Error err = tls_ctx->init_client(MBEDTLS_SSL_TRANSPORT_DATAGRAM, p_hostname, p_options.is_valid() ? p_options : TLSOptions::client());
ERR_FAIL_COND_V(err != OK, err);
Expand All @@ -135,7 +135,7 @@ Error PacketPeerMbedDTLS::connect_to_peer(Ref<PacketPeerUDP> p_base, const Strin
}

Error PacketPeerMbedDTLS::accept_peer(Ref<PacketPeerUDP> p_base, Ref<TLSOptions> p_options, Ref<CookieContextMbedTLS> p_cookies) {
ERR_FAIL_COND_V(!p_base.is_valid() || !p_base->is_socket_connected(), ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(p_base.is_null() || !p_base->is_socket_connected(), ERR_INVALID_PARAMETER);

Error err = tls_ctx->init_server(MBEDTLS_SSL_TRANSPORT_DATAGRAM, p_options, p_cookies);
ERR_FAIL_COND_V(err != OK, err);
Expand Down Expand Up @@ -216,7 +216,7 @@ void PacketPeerMbedDTLS::poll() {
return;
}

ERR_FAIL_COND(!base.is_valid());
ERR_FAIL_COND(base.is_null());

int ret = mbedtls_ssl_read(tls_ctx->get_context(), nullptr, 0);

Expand Down
2 changes: 1 addition & 1 deletion modules/mbedtls/stream_peer_mbedtls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ Error StreamPeerMbedTLS::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r

void StreamPeerMbedTLS::poll() {
ERR_FAIL_COND(status != STATUS_CONNECTED && status != STATUS_HANDSHAKING);
ERR_FAIL_COND(!base.is_valid());
ERR_FAIL_COND(base.is_null());

if (status == STATUS_HANDSHAKING) {
_do_handshake();
Expand Down
16 changes: 8 additions & 8 deletions modules/mono/csharp_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,14 +1473,14 @@ Object *CSharpInstance::get_owner() {
}

bool CSharpInstance::set(const StringName &p_name, const Variant &p_value) {
ERR_FAIL_COND_V(!script.is_valid(), false);
ERR_FAIL_COND_V(script.is_null(), false);

return GDMonoCache::managed_callbacks.CSharpInstanceBridge_Set(
gchandle.get_intptr(), &p_name, &p_value);
}

bool CSharpInstance::get(const StringName &p_name, Variant &r_ret) const {
ERR_FAIL_COND_V(!script.is_valid(), false);
ERR_FAIL_COND_V(script.is_null(), false);

Variant ret_value;

Expand All @@ -1501,7 +1501,7 @@ void CSharpInstance::get_property_list(List<PropertyInfo> *p_properties) const {

// Call _get_property_list

ERR_FAIL_COND(!script.is_valid());
ERR_FAIL_COND(script.is_null());

StringName method = SNAME("_get_property_list");

Expand Down Expand Up @@ -1546,7 +1546,7 @@ Variant::Type CSharpInstance::get_property_type(const StringName &p_name, bool *
}

bool CSharpInstance::property_can_revert(const StringName &p_name) const {
ERR_FAIL_COND_V(!script.is_valid(), false);
ERR_FAIL_COND_V(script.is_null(), false);

Variant name_arg = p_name;
const Variant *args[1] = { &name_arg };
Expand All @@ -1564,7 +1564,7 @@ bool CSharpInstance::property_can_revert(const StringName &p_name) const {
}

void CSharpInstance::validate_property(PropertyInfo &p_property) const {
ERR_FAIL_COND(!script.is_valid());
ERR_FAIL_COND(script.is_null());

Variant property_arg = (Dictionary)p_property;
const Variant *args[1] = { &property_arg };
Expand All @@ -1582,7 +1582,7 @@ void CSharpInstance::validate_property(PropertyInfo &p_property) const {
}

bool CSharpInstance::property_get_revert(const StringName &p_name, Variant &r_ret) const {
ERR_FAIL_COND_V(!script.is_valid(), false);
ERR_FAIL_COND_V(script.is_null(), false);

Variant name_arg = p_name;
const Variant *args[1] = { &name_arg };
Expand All @@ -1609,7 +1609,7 @@ void CSharpInstance::get_method_list(List<MethodInfo> *p_list) const {
}

bool CSharpInstance::has_method(const StringName &p_method) const {
if (!script.is_valid()) {
if (script.is_null()) {
return false;
}

Expand Down Expand Up @@ -1650,7 +1650,7 @@ int CSharpInstance::get_method_argument_count(const StringName &p_method, bool *
}

Variant CSharpInstance::callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
ERR_FAIL_COND_V(!script.is_valid(), Variant());
ERR_FAIL_COND_V(script.is_null(), Variant());

Variant ret;
GDMonoCache::managed_callbacks.CSharpInstanceBridge_Call(
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/runtime_interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ void godotsharp_weakref(Object *p_ptr, Ref<RefCounted> *r_weak_ref) {

if (rc) {
Ref<RefCounted> r = rc;
if (!r.is_valid()) {
if (r.is_null()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/multiplayer/editor/replication_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ void ReplicationEditor::_update_config() {
tree->clear();
tree->create_item();
drop_label->set_visible(true);
if (!config.is_valid()) {
if (config.is_null()) {
return;
}
TypedArray<NodePath> props = config->get_properties();
Expand Down
Loading

0 comments on commit d480379

Please sign in to comment.