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

Cleanup of raw nullptr checks with Ref #96292

Merged
merged 1 commit into from
Sep 3, 2024
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
2 changes: 1 addition & 1 deletion core/extension/gdextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ GDExtensionInterfaceFunctionPtr GDExtension::get_interface_function(const String
}

Error GDExtension::open_library(const String &p_path, const Ref<GDExtensionLoader> &p_loader) {
ERR_FAIL_NULL_V_MSG(p_loader, FAILED, "Can't open GDExtension without a loader.");
ERR_FAIL_COND_V_MSG(p_loader.is_null(), FAILED, "Can't open GDExtension without a loader.");
loader = p_loader;

Error err = loader->open_library(p_path);
Expand Down
4 changes: 2 additions & 2 deletions core/io/file_access_encrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <stdio.h>

Error FileAccessEncrypted::open_and_parse(Ref<FileAccess> p_base, const Vector<uint8_t> &p_key, Mode p_mode, bool p_with_magic) {
ERR_FAIL_COND_V_MSG(file != nullptr, ERR_ALREADY_IN_USE, "Can't open file while another file from path '" + file->get_path_absolute() + "' is open.");
ERR_FAIL_COND_V_MSG(file.is_valid(), ERR_ALREADY_IN_USE, "Can't open file while another file from path '" + file->get_path_absolute() + "' is open.");
ERR_FAIL_COND_V(p_key.size() != 32, ERR_INVALID_PARAMETER);

pos = 0;
Expand Down Expand Up @@ -162,7 +162,7 @@ void FileAccessEncrypted::_close() {
}

bool FileAccessEncrypted::is_open() const {
return file != nullptr;
return file.is_valid();
}

String FileAccessEncrypted::get_path() const {
Expand Down
2 changes: 1 addition & 1 deletion core/io/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4225,7 +4225,7 @@ Dictionary Image::compute_image_metrics(const Ref<Image> p_compared_image, bool
result["root_mean_squared"] = INFINITY;
result["peak_snr"] = 0.0f;

ERR_FAIL_NULL_V(p_compared_image, result);
ERR_FAIL_COND_V(p_compared_image.is_null(), result);
Error err = OK;
Ref<Image> compared_image = duplicate(true);
if (compared_image->is_compressed()) {
Expand Down
4 changes: 2 additions & 2 deletions core/io/plist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ bool PList::load_string(const String &p_string, String &r_err_out) {
}

PackedByteArray PList::save_asn1() const {
if (root == nullptr) {
if (root.is_null()) {
ERR_FAIL_V_MSG(PackedByteArray(), "PList: Invalid PList, no root node.");
}
size_t size = root->get_asn1_size(1);
Expand Down Expand Up @@ -848,7 +848,7 @@ PackedByteArray PList::save_asn1() const {
}

String PList::save_text() const {
if (root == nullptr) {
if (root.is_null()) {
ERR_FAIL_V_MSG(String(), "PList: Invalid PList, no root node.");
}

Expand Down
2 changes: 1 addition & 1 deletion editor/animation_bezier_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ void AnimationBezierTrackEdit::set_root(Node *p_root) {

void AnimationBezierTrackEdit::set_filtered(bool p_filtered) {
is_filtered = p_filtered;
if (animation == nullptr) {
if (animation.is_null()) {
return;
}
String base_path = animation->track_get_path(selected_track);
Expand Down
2 changes: 1 addition & 1 deletion editor/export/editor_export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Vector<String> EditorExportPlugin::get_ios_project_static_libs() const {
}

Variant EditorExportPlugin::get_option(const StringName &p_name) const {
ERR_FAIL_NULL_V(export_preset, Variant());
ERR_FAIL_COND_V(export_preset.is_null(), Variant());
return export_preset->get(p_name);
}

Expand Down
2 changes: 1 addition & 1 deletion editor/import/3d/resource_importer_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ static String _fixstr(const String &p_what, const String &p_str) {
}

static void _pre_gen_shape_list(Ref<ImporterMesh> &mesh, Vector<Ref<Shape3D>> &r_shape_list, bool p_convex) {
ERR_FAIL_NULL_MSG(mesh, "Cannot generate shape list with null mesh value.");
ERR_FAIL_COND_MSG(mesh.is_null(), "Cannot generate shape list with null mesh value.");
if (!p_convex) {
Ref<ConcavePolygonShape3D> shape = mesh->create_trimesh_shape();
r_shape_list.push_back(shape);
Expand Down
16 changes: 8 additions & 8 deletions editor/import/dynamic_font_import_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ void DynamicFontImportSettingsDialog::_variation_add() {
Ref<DynamicFontImportSettingsData> import_variation_data;
import_variation_data.instantiate();
import_variation_data->owner = this;
ERR_FAIL_NULL(import_variation_data);
ERR_FAIL_COND(import_variation_data.is_null());

for (List<ResourceImporter::ImportOption>::Element *E = options_variations.front(); E; E = E->next()) {
import_variation_data->defaults[E->get().option.name] = E->get().default_value;
Expand All @@ -529,7 +529,7 @@ void DynamicFontImportSettingsDialog::_variation_selected() {
TreeItem *vars_item = vars_list->get_selected();
if (vars_item) {
Ref<DynamicFontImportSettingsData> import_variation_data = vars_item->get_metadata(0);
ERR_FAIL_NULL(import_variation_data);
ERR_FAIL_COND(import_variation_data.is_null());

inspector_vars->edit(import_variation_data.ptr());
import_variation_data->notify_property_list_changed();
Expand Down Expand Up @@ -588,14 +588,14 @@ void DynamicFontImportSettingsDialog::_variations_validate() {
}
for (TreeItem *vars_item_a = vars_list_root->get_first_child(); vars_item_a; vars_item_a = vars_item_a->get_next()) {
Ref<DynamicFontImportSettingsData> import_variation_data_a = vars_item_a->get_metadata(0);
ERR_FAIL_NULL(import_variation_data_a);
ERR_FAIL_COND(import_variation_data_a.is_null());

for (TreeItem *vars_item_b = vars_list_root->get_first_child(); vars_item_b; vars_item_b = vars_item_b->get_next()) {
if (vars_item_b != vars_item_a) {
bool match = true;
for (const KeyValue<StringName, Variant> &E : import_variation_data_a->settings) {
Ref<DynamicFontImportSettingsData> import_variation_data_b = vars_item_b->get_metadata(0);
ERR_FAIL_NULL(import_variation_data_b);
ERR_FAIL_COND(import_variation_data_b.is_null());
match = match && (import_variation_data_b->settings[E.key] == E.value);
}
if (match) {
Expand Down Expand Up @@ -956,7 +956,7 @@ void DynamicFontImportSettingsDialog::_re_import() {
Array configurations;
for (TreeItem *vars_item = vars_list_root->get_first_child(); vars_item; vars_item = vars_item->get_next()) {
Ref<DynamicFontImportSettingsData> import_variation_data = vars_item->get_metadata(0);
ERR_FAIL_NULL(import_variation_data);
ERR_FAIL_COND(import_variation_data.is_null());

Dictionary preload_config;
preload_config["name"] = vars_item->get_text(0);
Expand Down Expand Up @@ -1107,7 +1107,7 @@ void DynamicFontImportSettingsDialog::open_settings(const String &p_path) {
inspector_general->edit(nullptr);

text_settings_data.instantiate();
ERR_FAIL_NULL(text_settings_data);
ERR_FAIL_COND(text_settings_data.is_null());

text_settings_data->owner = this;

Expand Down Expand Up @@ -1137,7 +1137,7 @@ void DynamicFontImportSettingsDialog::open_settings(const String &p_path) {

Ref<ConfigFile> config;
config.instantiate();
ERR_FAIL_NULL(config);
ERR_FAIL_COND(config.is_null());

Error err = config->load(p_path + ".import");
print_verbose("Loading import settings:");
Expand Down Expand Up @@ -1169,7 +1169,7 @@ void DynamicFontImportSettingsDialog::open_settings(const String &p_path) {

Ref<DynamicFontImportSettingsData> import_variation_data_custom;
import_variation_data_custom.instantiate();
ERR_FAIL_NULL(import_variation_data_custom);
ERR_FAIL_COND(import_variation_data_custom.is_null());

import_variation_data_custom->owner = this;
for (List<ResourceImporter::ImportOption>::Element *F = options_variations.front(); F; F = F->next()) {
Expand Down
2 changes: 1 addition & 1 deletion editor/import/resource_importer_layered_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ void ResourceImporterLayeredTexture::_check_compress_ctex(const String &p_source
}

bool can_compress_hdr = r_texture_import->hdr_compression > 0;
ERR_FAIL_NULL(r_texture_import->image);
ERR_FAIL_COND(r_texture_import->image.is_null());
bool is_hdr = (r_texture_import->image->get_format() >= Image::FORMAT_RF && r_texture_import->image->get_format() <= Image::FORMAT_RGBE9995);
ERR_FAIL_NULL(r_texture_import->slices);
// Can compress hdr, but hdr with alpha is not compressible.
Expand Down
2 changes: 1 addition & 1 deletion editor/import_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void ImportDock::_add_keep_import_option(const String &p_importer_name) {
void ImportDock::_update_options(const String &p_path, const Ref<ConfigFile> &p_config) {
// Set the importer class to fetch the correct class in the XML class reference.
// This allows tooltips to display when hovering properties.
if (params->importer != nullptr) {
if (params->importer.is_valid()) {
// Null check to avoid crashing if the "Keep File (exported as is)" mode is selected.
import_opts->set_object_class(params->importer->get_class_name());
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/node_3d_editor_gizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ void EditorNode3DGizmoPlugin::create_handle_material(const String &p_name, bool

handle_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
handle_material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true);
Ref<Texture2D> handle_t = p_icon != nullptr ? p_icon : EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Editor3DHandle"), EditorStringName(EditorIcons));
Ref<Texture2D> handle_t = p_icon.is_valid() ? p_icon : EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Editor3DHandle"), EditorStringName(EditorIcons));
handle_material->set_point_size(handle_t->get_width());
handle_material->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, handle_t);
handle_material->set_albedo(Color(1, 1, 1));
Expand Down
8 changes: 4 additions & 4 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4506,8 +4506,8 @@ bool Node3DEditorViewport::_create_instance(Node *p_parent, const String &p_path

Node *instantiated_scene = nullptr;

if (mesh != nullptr || scene != nullptr) {
if (mesh != nullptr) {
if (mesh.is_valid() || scene.is_valid()) {
if (mesh.is_valid()) {
MeshInstance3D *mesh_instance = memnew(MeshInstance3D);
mesh_instance->set_mesh(mesh);

Expand Down Expand Up @@ -4538,7 +4538,7 @@ bool Node3DEditorViewport::_create_instance(Node *p_parent, const String &p_path
}
}

if (scene != nullptr) {
if (scene.is_valid()) {
instantiated_scene->set_scene_file_path(ProjectSettings::get_singleton()->localize_path(p_path));
}

Expand Down Expand Up @@ -9291,7 +9291,7 @@ struct _GizmoPluginNameComparator {
};

void Node3DEditor::add_gizmo_plugin(Ref<EditorNode3DGizmoPlugin> p_plugin) {
ERR_FAIL_NULL(p_plugin.ptr());
ERR_FAIL_COND(p_plugin.is_null());

gizmo_plugins_by_priority.push_back(p_plugin);
gizmo_plugins_by_priority.sort_custom<_GizmoPluginPriorityComparator>();
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/path_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
Vector2 gpoint = mm->get_position();

Ref<Curve2D> curve = node->get_curve();
if (curve == nullptr) {
if (curve.is_null()) {
return true;
}
if (curve->get_point_count() < 2) {
Expand Down
34 changes: 17 additions & 17 deletions editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ void ScriptEditor::_set_execution(Ref<RefCounted> p_script, int p_line) {
continue;
}

if ((scr != nullptr && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == scr->get_path()) {
if ((scr.is_valid() && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == scr->get_path()) {
se->set_executing_line(p_line);
}
}
Expand All @@ -526,7 +526,7 @@ void ScriptEditor::_clear_execution(Ref<RefCounted> p_script) {
continue;
}

if ((scr != nullptr && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == scr->get_path()) {
if ((scr.is_valid() && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == scr->get_path()) {
se->clear_executing_line();
}
}
Expand Down Expand Up @@ -711,7 +711,7 @@ void ScriptEditor::_go_to_tab(int p_idx) {
}

Ref<Script> scr = Object::cast_to<ScriptEditorBase>(c)->get_edited_resource();
if (scr != nullptr) {
if (scr.is_valid()) {
notify_script_changed(scr);
}

Expand Down Expand Up @@ -1017,7 +1017,7 @@ void ScriptEditor::_resave_scripts(const String &p_str) {
}

Ref<TextFile> text_file = scr;
if (text_file != nullptr) {
if (text_file.is_valid()) {
se->apply_code();
_save_text_file(text_file, text_file->get_path());
break;
Expand Down Expand Up @@ -1228,7 +1228,7 @@ Ref<Script> ScriptEditor::_get_current_script() {

if (current) {
Ref<Script> scr = current->get_edited_resource();
return scr != nullptr ? scr : nullptr;
return scr.is_valid() ? scr : nullptr;
} else {
return nullptr;
}
Expand Down Expand Up @@ -1420,7 +1420,7 @@ void ScriptEditor::_menu_option(int p_option) {
Ref<TextFile> text_file = resource;
Ref<Script> scr = resource;

if (text_file != nullptr) {
if (text_file.is_valid()) {
file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
file_dialog_option = FILE_SAVE_AS;
Expand Down Expand Up @@ -1449,7 +1449,7 @@ void ScriptEditor::_menu_option(int p_option) {

case FILE_TOOL_RELOAD_SOFT: {
Ref<Script> scr = current->get_edited_resource();
if (scr == nullptr || scr.is_null()) {
if (scr.is_null()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These cases were redunant

EditorNode::get_singleton()->show_warning(TTR("Can't obtain the script for reloading."));
break;
}
Expand All @@ -1463,7 +1463,7 @@ void ScriptEditor::_menu_option(int p_option) {

case FILE_RUN: {
Ref<Script> scr = current->get_edited_resource();
if (scr == nullptr || scr.is_null()) {
if (scr.is_null()) {
EditorToaster::get_singleton()->popup_str(TTR("Cannot run the edited file because it's not a script."), EditorToaster::SEVERITY_WARNING);
break;
}
Expand Down Expand Up @@ -1796,7 +1796,7 @@ void ScriptEditor::_close_builtin_scripts_from_scene(const String &p_scene) {

if (se) {
Ref<Script> scr = se->get_edited_resource();
if (scr == nullptr || !scr.is_valid()) {
if (scr.is_null()) {
continue;
}

Expand Down Expand Up @@ -2500,7 +2500,7 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col,
continue;
}

if ((scr != nullptr && se->get_edited_resource() == p_resource) || se->get_edited_resource()->get_path() == p_resource->get_path()) {
if ((scr.is_valid() && se->get_edited_resource() == p_resource) || se->get_edited_resource()->get_path() == p_resource->get_path()) {
if (should_open) {
se->enable_editor(this);

Expand Down Expand Up @@ -2550,7 +2550,7 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col,

PackedStringArray languages = highlighter->_get_supported_languages();
// If script try language, else use extension.
if (scr != nullptr) {
if (scr.is_valid()) {
if (languages.has(scr->get_language()->get_name())) {
se->set_syntax_highlighter(highlighter);
highlighter_set = true;
Expand Down Expand Up @@ -2660,7 +2660,7 @@ void ScriptEditor::save_current_script() {
Ref<TextFile> text_file = resource;
Ref<Script> scr = resource;

if (text_file != nullptr) {
if (text_file.is_valid()) {
current->apply_code();
_save_text_file(text_file, text_file->get_path());
return;
Expand Down Expand Up @@ -2711,7 +2711,7 @@ void ScriptEditor::save_all_scripts() {
Ref<TextFile> text_file = edited_res;
Ref<Script> scr = edited_res;

if (text_file != nullptr) {
if (text_file.is_valid()) {
_save_text_file(text_file, text_file->get_path());
continue;
}
Expand Down Expand Up @@ -2788,7 +2788,7 @@ void ScriptEditor::_reload_scripts(bool p_refresh_only) {
}

Ref<JSON> json = edited_res;
if (json != nullptr) {
if (json.is_valid()) {
Ref<JSON> rel_json = ResourceLoader::load(json->get_path(), json->get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE);
ERR_CONTINUE(!rel_json.is_valid());
json->parse(rel_json->get_parsed_text(), true);
Expand Down Expand Up @@ -3338,7 +3338,7 @@ void ScriptEditor::_make_script_list_context_menu() {
context_menu->add_separator();
if (se) {
Ref<Script> scr = se->get_edited_resource();
if (scr != nullptr) {
if (scr.is_valid()) {
if (!scr.is_null() && scr->is_tool()) {
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/reload_script_soft"), FILE_TOOL_RELOAD_SOFT);
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/run_file"), FILE_RUN);
Expand Down Expand Up @@ -3685,7 +3685,7 @@ void ScriptEditor::_update_history_pos(int p_new_pos) {
seb->ensure_focus();

Ref<Script> scr = seb->get_edited_resource();
if (scr != nullptr) {
if (scr.is_valid()) {
notify_script_changed(scr);
}
}
Expand Down Expand Up @@ -3724,7 +3724,7 @@ Vector<Ref<Script>> ScriptEditor::get_open_scripts() const {
}

Ref<Script> scr = se->get_edited_resource();
if (scr != nullptr) {
if (scr.is_valid()) {
out_scripts.push_back(scr);
}
}
Expand Down
Loading
Loading