Merge pull request #96292 from AThousandShips/null_check_ref_fix

Cleanup of raw `nullptr` checks with `Ref`
This commit is contained in:
Rémi Verschelde
2024-09-03 16:13:55 +02:00
48 changed files with 169 additions and 170 deletions
+1 -1
View File
@@ -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));
+4 -4
View File
@@ -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);
@@ -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));
}
@@ -9292,7 +9292,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>();
+1 -1
View File
@@ -300,7 +300,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) {
+17 -17
View File
@@ -511,7 +511,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);
}
}
@@ -527,7 +527,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();
}
}
@@ -712,7 +712,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);
}
@@ -1018,7 +1018,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;
@@ -1229,7 +1229,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;
}
@@ -1431,7 +1431,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;
@@ -1460,7 +1460,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()) {
EditorNode::get_singleton()->show_warning(TTR("Can't obtain the script for reloading."));
break;
}
@@ -1474,7 +1474,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;
}
@@ -1807,7 +1807,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;
}
@@ -2511,7 +2511,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);
@@ -2561,7 +2561,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;
@@ -2671,7 +2671,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;
@@ -2722,7 +2722,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;
}
@@ -2799,7 +2799,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);
@@ -3354,7 +3354,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);
@@ -3712,7 +3712,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);
}
}
@@ -3751,7 +3751,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);
}
}
+7 -7
View File
@@ -104,12 +104,12 @@ void TextEditor::set_edited_resource(const Ref<Resource> &p_res) {
edited_res = p_res;
Ref<TextFile> text_file = edited_res;
if (text_file != nullptr) {
if (text_file.is_valid()) {
code_editor->get_text_editor()->set_text(text_file->get_text());
}
Ref<JSON> json_file = edited_res;
if (json_file != nullptr) {
if (json_file.is_valid()) {
code_editor->get_text_editor()->set_text(json_file->get_parsed_text());
}
@@ -169,12 +169,12 @@ void TextEditor::reload_text() {
int v = te->get_v_scroll();
Ref<TextFile> text_file = edited_res;
if (text_file != nullptr) {
if (text_file.is_valid()) {
te->set_text(text_file->get_text());
}
Ref<JSON> json_file = edited_res;
if (json_file != nullptr) {
if (json_file.is_valid()) {
te->set_text(json_file->get_parsed_text());
}
@@ -194,7 +194,7 @@ void TextEditor::_validate_script() {
emit_signal(SNAME("edited_script_changed"));
Ref<JSON> json_file = edited_res;
if (json_file != nullptr) {
if (json_file.is_valid()) {
CodeEdit *te = code_editor->get_text_editor();
te->set_line_background_color(code_editor->get_error_pos().x, Color(0, 0, 0, 0));
@@ -245,12 +245,12 @@ void TextEditor::_bookmark_item_pressed(int p_idx) {
void TextEditor::apply_code() {
Ref<TextFile> text_file = edited_res;
if (text_file != nullptr) {
if (text_file.is_valid()) {
text_file->set_text(code_editor->get_text_editor()->get_text());
}
Ref<JSON> json_file = edited_res;
if (json_file != nullptr) {
if (json_file.is_valid()) {
json_file->parse(code_editor->get_text_editor()->get_text(), true);
}
code_editor->get_text_editor()->get_syntax_highlighter()->update_cache();
+1 -1
View File
@@ -169,7 +169,7 @@ void EditorInspectorPluginTexture::parse_begin(Object *p_object) {
Ref<Image> image(Object::cast_to<Image>(p_object));
texture = ImageTexture::create_from_image(image);
ERR_FAIL_NULL_MSG(texture, "Failed to create the texture from an invalid image.");
ERR_FAIL_COND_MSG(texture.is_null(), "Failed to create the texture from an invalid image.");
}
add_custom_control(memnew(TexturePreview(texture, true)));