Skip to content

Commit

Permalink
Merge pull request #81705 from AThousandShips/null_check_editor
Browse files Browse the repository at this point in the history
[Editor] Replace `ERR_FAIL_COND` with `ERR_FAIL_NULL` where applicable
  • Loading branch information
akien-mga committed Sep 16, 2023
2 parents 691eecd + 75ee58f commit cdef53d
Show file tree
Hide file tree
Showing 61 changed files with 217 additions and 217 deletions.
20 changes: 10 additions & 10 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ void AnimationTrackKeyEdit::_fix_node_path(Variant &value) {
Node *root = EditorNode::get_singleton()->get_tree()->get_root();

Node *np_node = root->get_node(np);
ERR_FAIL_COND(!np_node);
ERR_FAIL_NULL(np_node);

Node *edited_node = root->get_node(base);
ERR_FAIL_COND(!edited_node);
ERR_FAIL_NULL(edited_node);

value = edited_node->get_path_to(np_node);
}
Expand Down Expand Up @@ -656,10 +656,10 @@ void AnimationMultiTrackKeyEdit::_fix_node_path(Variant &value, NodePath &base)
Node *root = EditorNode::get_singleton()->get_tree()->get_root();

Node *np_node = root->get_node(np);
ERR_FAIL_COND(!np_node);
ERR_FAIL_NULL(np_node);

Node *edited_node = root->get_node(base);
ERR_FAIL_COND(!edited_node);
ERR_FAIL_NULL(edited_node);

value = edited_node->get_path_to(np_node);
}
Expand Down Expand Up @@ -3703,7 +3703,7 @@ void AnimationTrackEditor::_insert_track(bool p_reset_wanted, bool p_create_bezi
}

void AnimationTrackEditor::insert_transform_key(Node3D *p_node, const String &p_sub, const Animation::TrackType p_type, const Variant p_value) {
ERR_FAIL_COND(!root);
ERR_FAIL_NULL(root);
ERR_FAIL_COND_MSG(
(p_type != Animation::TYPE_POSITION_3D && p_type != Animation::TYPE_ROTATION_3D && p_type != Animation::TYPE_SCALE_3D),
"Track type must be Position/Rotation/Scale 3D.");
Expand Down Expand Up @@ -3746,7 +3746,7 @@ void AnimationTrackEditor::insert_transform_key(Node3D *p_node, const String &p_
}

bool AnimationTrackEditor::has_track(Node3D *p_node, const String &p_sub, const Animation::TrackType p_type) {
ERR_FAIL_COND_V(!root, false);
ERR_FAIL_NULL_V(root, false);
if (!keying) {
return false;
}
Expand Down Expand Up @@ -3802,7 +3802,7 @@ void AnimationTrackEditor::_insert_animation_key(NodePath p_path, const Variant
}

void AnimationTrackEditor::insert_node_value_key(Node *p_node, const String &p_property, const Variant &p_value, bool p_only_if_exists) {
ERR_FAIL_COND(!root);
ERR_FAIL_NULL(root);

// Let's build a node path.
Node *node = p_node;
Expand Down Expand Up @@ -3899,7 +3899,7 @@ void AnimationTrackEditor::insert_node_value_key(Node *p_node, const String &p_p
void AnimationTrackEditor::insert_value_key(const String &p_property, const Variant &p_value, bool p_advance) {
EditorSelectionHistory *history = EditorNode::get_singleton()->get_editor_selection_history();

ERR_FAIL_COND(!root);
ERR_FAIL_NULL(root);
ERR_FAIL_COND(history->get_path_size() == 0);
Object *obj = ObjectDB::get_instance(history->get_path_object(0));
ERR_FAIL_COND(!Object::cast_to<Node>(obj));
Expand Down Expand Up @@ -4685,9 +4685,9 @@ void AnimationTrackEditor::_dropped_track(int p_from_track, int p_to_track) {
}

void AnimationTrackEditor::_new_track_node_selected(NodePath p_path) {
ERR_FAIL_COND(!root);
ERR_FAIL_NULL(root);
Node *node = get_node(p_path);
ERR_FAIL_COND(!node);
ERR_FAIL_NULL(node);
NodePath path_to = root->get_path_to(node, true);

if (adding_track_type == Animation::TYPE_BLEND_SHAPE && !node->is_class("MeshInstance3D")) {
Expand Down
4 changes: 2 additions & 2 deletions editor/connections_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ void ConnectionsDock::_filter_changed(const String &p_text) {
void ConnectionsDock::_make_or_edit_connection() {
NodePath dst_path = connect_dialog->get_dst_path();
Node *target = selected_node->get_node(dst_path);
ERR_FAIL_COND(!target);
ERR_FAIL_NULL(target);

ConnectDialog::ConnectionData cd;
cd.source = connect_dialog->get_source();
Expand Down Expand Up @@ -1066,7 +1066,7 @@ void ConnectionsDock::_open_connection_dialog(TreeItem &p_item) {
*/
void ConnectionsDock::_open_edit_connection_dialog(TreeItem &p_item) {
TreeItem *signal_item = p_item.get_parent();
ERR_FAIL_COND(!signal_item);
ERR_FAIL_NULL(signal_item);

Connection connection = p_item.get_metadata(0);
ConnectDialog::ConnectionData cd = connection;
Expand Down
8 changes: 4 additions & 4 deletions editor/debugger/editor_debugger_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ template <typename Func>
void _for_all(TabContainer *p_node, const Func &p_func) {
for (int i = 0; i < p_node->get_tab_count(); i++) {
ScriptEditorDebugger *dbg = Object::cast_to<ScriptEditorDebugger>(p_node->get_tab_control(i));
ERR_FAIL_COND(!dbg);
ERR_FAIL_NULL(dbg);
p_func(dbg);
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ ScriptEditorDebugger *EditorDebuggerNode::_add_debugger() {

void EditorDebuggerNode::_stack_frame_selected(int p_debugger) {
const ScriptEditorDebugger *dbg = get_debugger(p_debugger);
ERR_FAIL_COND(!dbg);
ERR_FAIL_NULL(dbg);
if (dbg != get_current_debugger()) {
return;
}
Expand Down Expand Up @@ -405,7 +405,7 @@ void EditorDebuggerNode::_update_errors() {

void EditorDebuggerNode::_debugger_stopped(int p_id) {
ScriptEditorDebugger *dbg = get_debugger(p_id);
ERR_FAIL_COND(!dbg);
ERR_FAIL_NULL(dbg);

bool found = false;
_for_all(tabs, [&](ScriptEditorDebugger *p_debugger) {
Expand Down Expand Up @@ -603,7 +603,7 @@ void EditorDebuggerNode::_remote_tree_button_pressed(Object *p_item, int p_colum
}

TreeItem *item = Object::cast_to<TreeItem>(p_item);
ERR_FAIL_COND(!item);
ERR_FAIL_NULL(item);

if (p_id == EditorDebuggerTree::BUTTON_SUBSCENE) {
remote_scene_tree->emit_signal(SNAME("open"), item->get_meta("scene_file_path"));
Expand Down
2 changes: 1 addition & 1 deletion editor/debugger/editor_debugger_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ String EditorDebuggerTree::get_selected_path() {
}

String EditorDebuggerTree::_get_path(TreeItem *p_item) {
ERR_FAIL_COND_V(!p_item, "");
ERR_FAIL_NULL_V(p_item, "");

if (p_item->get_parent() == nullptr) {
return "/root";
Expand Down
2 changes: 1 addition & 1 deletion editor/debugger/editor_performance_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ EditorPerformanceProfiler::Monitor::Monitor(String p_name, String p_base, int p_
}

void EditorPerformanceProfiler::Monitor::update_value(float p_value) {
ERR_FAIL_COND(!item);
ERR_FAIL_NULL(item);
String label = EditorPerformanceProfiler::_create_label(p_value, type);
String tooltip = label;
switch (type) {
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_audio_buses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,9 @@ void EditorAudioBus::_effect_add(int p_which) {
StringName name = effect_options->get_item_metadata(p_which);

Object *fx = ClassDB::instantiate(name);
ERR_FAIL_COND(!fx);
ERR_FAIL_NULL(fx);
AudioEffect *afx = Object::cast_to<AudioEffect>(fx);
ERR_FAIL_COND(!afx);
ERR_FAIL_NULL(afx);
Ref<AudioEffect> afxr = Ref<AudioEffect>(afx);

afxr->set_name(effect_options->get_item_text(p_which));
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_autoload_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,14 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) {

Object *obj = ClassDB::instantiate(ibt);

ERR_FAIL_COND_V_MSG(!obj, nullptr, vformat("Cannot instance script for Autoload, expected 'Node' inheritance, got: %s.", ibt));
ERR_FAIL_NULL_V_MSG(obj, nullptr, vformat("Cannot instance script for Autoload, expected 'Node' inheritance, got: %s.", ibt));

n = Object::cast_to<Node>(obj);
n->set_script(scr);
}
}

ERR_FAIL_COND_V_MSG(!n, nullptr, vformat("Path in Autoload not a node or script: %s.", p_path));
ERR_FAIL_NULL_V_MSG(n, nullptr, vformat("Path in Autoload not a node or script: %s.", p_path));

return n;
}
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void EditorSelectionHistory::cleanup_history() {

void EditorSelectionHistory::add_object(ObjectID p_object, const String &p_property, bool p_inspector_only) {
Object *obj = ObjectDB::get_instance(p_object);
ERR_FAIL_COND(!obj);
ERR_FAIL_NULL(obj);
RefCounted *r = Object::cast_to<RefCounted>(obj);
_Object o;
if (r) {
Expand Down Expand Up @@ -700,7 +700,7 @@ bool EditorData::check_and_update_scene(int p_idx) {
ERR_FAIL_COND_V(err != OK, false);
ep.step(TTR("Updating scene..."), 1);
Node *new_scene = pscene->instantiate(PackedScene::GEN_EDIT_STATE_MAIN);
ERR_FAIL_COND_V(!new_scene, false);
ERR_FAIL_NULL_V(new_scene, false);

// Transfer selection.
List<Node *> new_selection;
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3955,7 +3955,7 @@ void EditorInspector::_property_pinned(const String &p_path, bool p_pinned) {
}

Node *node = Object::cast_to<Node>(object);
ERR_FAIL_COND(!node);
ERR_FAIL_NULL(node);

EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(vformat(p_pinned ? TTR("Pinned %s") : TTR("Unpinned %s"), p_path));
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ void EditorInterface::create() {
}

void EditorInterface::free() {
ERR_FAIL_COND(singleton == nullptr);
ERR_FAIL_NULL(singleton);
memdelete(singleton);
}

Expand Down
24 changes: 12 additions & 12 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ void EditorNode::_dialog_action(String p_file) {
saving_resource = Ref<Resource>();
ObjectID current_id = editor_history.get_current();
Object *current_obj = current_id.is_valid() ? ObjectDB::get_instance(current_id) : nullptr;
ERR_FAIL_COND(!current_obj);
ERR_FAIL_NULL(current_obj);
current_obj->notify_property_list_changed();
} break;
case SETTINGS_LAYOUT_SAVE: {
Expand Down Expand Up @@ -2281,7 +2281,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) {

if (is_resource) {
Resource *current_res = Object::cast_to<Resource>(current_obj);
ERR_FAIL_COND(!current_res);
ERR_FAIL_NULL(current_res);

InspectorDock::get_inspector_singleton()->edit(current_res);
SceneTreeDock::get_singleton()->set_selected(nullptr);
Expand Down Expand Up @@ -2315,7 +2315,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) {
}
} else if (is_node) {
Node *current_node = Object::cast_to<Node>(current_obj);
ERR_FAIL_COND(!current_node);
ERR_FAIL_NULL(current_node);

InspectorDock::get_inspector_singleton()->edit(current_node);
if (current_node->is_inside_tree()) {
Expand Down Expand Up @@ -2950,9 +2950,9 @@ void EditorNode::_screenshot(bool p_use_utc) {

void EditorNode::_save_screenshot(NodePath p_path) {
Control *editor_main_screen = EditorInterface::get_singleton()->get_editor_main_screen();
ERR_FAIL_COND_MSG(!editor_main_screen, "Cannot get the editor main screen control.");
ERR_FAIL_NULL_MSG(editor_main_screen, "Cannot get the editor main screen control.");
Viewport *viewport = editor_main_screen->get_viewport();
ERR_FAIL_COND_MSG(!viewport, "Cannot get a viewport from the editor main screen.");
ERR_FAIL_NULL_MSG(viewport, "Cannot get a viewport from the editor main screen.");
Ref<ViewportTexture> texture = viewport->get_texture();
ERR_FAIL_COND_MSG(texture.is_null(), "Cannot get a viewport texture from the editor main screen.");
Ref<Image> img = texture->get_image();
Expand Down Expand Up @@ -3136,7 +3136,7 @@ void EditorNode::editor_select(int p_which) {
selecting = false;

EditorPlugin *new_editor = editor_table[p_which];
ERR_FAIL_COND(!new_editor);
ERR_FAIL_NULL(new_editor);

if (editor_plugin_screen == new_editor) {
return;
Expand Down Expand Up @@ -4169,7 +4169,7 @@ void EditorNode::stop_child_process(OS::ProcessID p_pid) {
}

Ref<Script> EditorNode::get_object_custom_type_base(const Object *p_object) const {
ERR_FAIL_COND_V(!p_object, nullptr);
ERR_FAIL_NULL_V(p_object, nullptr);

Ref<Script> scr = p_object->get_script();

Expand Down Expand Up @@ -4201,7 +4201,7 @@ Ref<Script> EditorNode::get_object_custom_type_base(const Object *p_object) cons
}

StringName EditorNode::get_object_custom_type_name(const Object *p_object) const {
ERR_FAIL_COND_V(!p_object, StringName());
ERR_FAIL_NULL_V(p_object, StringName());

Ref<Script> scr = p_object->get_script();
if (scr.is_null() && Object::cast_to<Script>(p_object)) {
Expand Down Expand Up @@ -4341,7 +4341,7 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p
}

bool EditorNode::is_object_of_custom_type(const Object *p_object, const StringName &p_class) {
ERR_FAIL_COND_V(!p_object, false);
ERR_FAIL_NULL_V(p_object, false);

Ref<Script> scr = p_object->get_script();
if (scr.is_null() && Object::cast_to<Script>(p_object)) {
Expand Down Expand Up @@ -4631,7 +4631,7 @@ void EditorNode::_dock_make_selected_float() {
}

void EditorNode::_dock_make_float(Control *p_dock, int p_slot_index, bool p_show_window) {
ERR_FAIL_COND(!p_dock);
ERR_FAIL_NULL(p_dock);

Size2 borders = Size2(4, 4) * EDSCALE;
// Remember size and position before removing it from the main window.
Expand Down Expand Up @@ -5810,7 +5810,7 @@ void EditorNode::remove_control_from_dock(Control *p_control) {
}
}

ERR_FAIL_COND_MSG(!dock, "Control was not in dock.");
ERR_FAIL_NULL_MSG(dock, "Control was not in dock.");

dock->remove_child(p_control);
_update_dock_slots_visibility();
Expand Down Expand Up @@ -6207,7 +6207,7 @@ void EditorNode::reload_instances_with_path_in_edited_scenes(const String &p_ins
instantiated_node = current_packed_scene->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE);
}

ERR_FAIL_COND(!instantiated_node);
ERR_FAIL_NULL(instantiated_node);

bool original_node_is_displayed_folded = original_node->is_displayed_folded();
bool original_node_scene_instance_load_placeholder = original_node->get_scene_instance_load_placeholder();
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void EditorPaths::create() {
}

void EditorPaths::free() {
ERR_FAIL_COND(singleton == nullptr);
ERR_FAIL_NULL(singleton);
memdelete(singleton);
}

Expand Down
2 changes: 1 addition & 1 deletion editor/editor_plugin_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void EditorPluginSettings::_plugin_activity_changed() {
}

TreeItem *ti = plugin_list->get_edited();
ERR_FAIL_COND(!ti);
ERR_FAIL_NULL(ti);
bool active = ti->is_checked(3);
String name = ti->get_metadata(0);

Expand Down
4 changes: 2 additions & 2 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2786,7 +2786,7 @@ void EditorPropertyNodePath::_node_selected(const NodePath &p_path) {

if (!base_node && Object::cast_to<RefCounted>(get_edited_object())) {
Node *to_node = get_node(p_path);
ERR_FAIL_COND(!to_node);
ERR_FAIL_NULL(to_node);
path = get_tree()->get_edited_scene_root()->get_path_to(to_node);
}

Expand Down Expand Up @@ -2899,7 +2899,7 @@ void EditorPropertyNodePath::update_property() {
}

Node *target_node = base_node->get_node(p);
ERR_FAIL_COND(!target_node);
ERR_FAIL_NULL(target_node);

if (String(target_node->get_name()).contains("@")) {
assign->set_icon(Ref<Texture2D>());
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_properties_array_dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ void EditorPropertyDictionary::update_property() {
}
}

ERR_FAIL_COND(!prop);
ERR_FAIL_NULL(prop);

prop->set_read_only(is_read_only());

Expand Down
2 changes: 1 addition & 1 deletion editor/editor_settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column
return;
}
TreeItem *ti = Object::cast_to<TreeItem>(p_item);
ERR_FAIL_COND_MSG(!ti, "Object passed is not a TreeItem");
ERR_FAIL_NULL_MSG(ti, "Object passed is not a TreeItem.");

ShortcutButton button_idx = (ShortcutButton)p_idx;

Expand Down
2 changes: 1 addition & 1 deletion editor/export/editor_export_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ String EditorExportPlatform::_export_customize(const String &p_path, LocalVector
Ref<PackedScene> ps = ResourceLoader::load(p_path, "PackedScene", ResourceFormatLoader::CACHE_MODE_IGNORE);
ERR_FAIL_COND_V(ps.is_null(), p_path);
Node *node = ps->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE); // Make sure the child scene root gets the correct inheritance chain.
ERR_FAIL_COND_V(node == nullptr, p_path);
ERR_FAIL_NULL_V(node, p_path);
if (!customize_scenes_plugins.is_empty()) {
for (Ref<EditorExportPlugin> &plugin : customize_scenes_plugins) {
Node *customized = plugin->_customize_scene(node, p_path);
Expand Down
2 changes: 1 addition & 1 deletion editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,7 @@ void FileSystemDock::_resource_created() {

ERR_FAIL_COND(!c);
Resource *r = Object::cast_to<Resource>(c);
ERR_FAIL_COND(!r);
ERR_FAIL_NULL(r);

PackedScene *scene = Object::cast_to<PackedScene>(r);
if (scene) {
Expand Down
4 changes: 2 additions & 2 deletions editor/find_in_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ void FindInFilesDialog::custom_action(const String &p_action) {
}

void FindInFilesDialog::_on_search_text_modified(String text) {
ERR_FAIL_COND(!_find_button);
ERR_FAIL_COND(!_replace_button);
ERR_FAIL_NULL(_find_button);
ERR_FAIL_NULL(_replace_button);

_find_button->set_disabled(get_search_text().is_empty());
_replace_button->set_disabled(get_search_text().is_empty());
Expand Down
Loading

0 comments on commit cdef53d

Please sign in to comment.