diff options
162 files changed, 1266 insertions, 1669 deletions
diff --git a/SConstruct b/SConstruct index aa5e3a98c8..128c5b0e92 100644 --- a/SConstruct +++ b/SConstruct @@ -484,6 +484,13 @@ if selected_platform in platform_list: if env['minizip']: env.Append(CPPDEFINES=['MINIZIP_ENABLED']) + editor_module_list = ['regex'] + for x in editor_module_list: + if not env['module_' + x + '_enabled']: + if env['tools']: + print("Build option 'module_" + x + "_enabled=no' cannot be used with 'tools=yes' (editor), only with 'tools=no' (export template).") + sys.exit(255) + if not env['verbose']: methods.no_verbose(sys, env) diff --git a/core/io/image_loader.h b/core/io/image_loader.h index ae4b72a534..f1fccc5230 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -41,20 +41,8 @@ @author Juan Linietsky <reduzio@gmail.com> */ -/** - * @class ImageScanLineLoader - * @author Juan Linietsky <reduzio@gmail.com> - * - - */ class ImageLoader; -/** - * @class ImageLoader - * Base Class and singleton for loading images from disk - * Can load images in one go, or by scanline - */ - class ImageFormatLoader { friend class ImageLoader; friend class ResourceFormatLoaderImage; diff --git a/core/math/transform.cpp b/core/math/transform.cpp index 7ff7cac914..4056975da8 100644 --- a/core/math/transform.cpp +++ b/core/math/transform.cpp @@ -213,3 +213,8 @@ Transform::Transform(const Basis &p_basis, const Vector3 &p_origin) : basis(p_basis), origin(p_origin) { } + +Transform::Transform(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t ox, real_t oy, real_t oz) { + basis = Basis(xx, xy, xz, yx, yy, yz, zx, zy, zz); + origin = Vector3(ox, oy, oz); +} diff --git a/core/math/transform.h b/core/math/transform.h index 2f43f6b035..df0a036218 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -108,6 +108,7 @@ public: operator String() const; + Transform(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t ox, real_t oy, real_t oz); Transform(const Basis &p_basis, const Vector3 &p_origin = Vector3()); Transform() {} }; diff --git a/core/os/dir_access.h b/core/os/dir_access.h index 704eedae5b..3c0528112b 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -97,6 +97,18 @@ public: virtual Error rename(String p_from, String p_to) = 0; virtual Error remove(String p_name) = 0; + // Meant for editor code when we want to quickly remove a file without custom + // handling (e.g. removing a cache file). + static void remove_file_or_error(String p_path) { + DirAccess *da = create(ACCESS_FILESYSTEM); + if (da->file_exists(p_path)) { + if (da->remove(p_path) != OK) { + ERR_FAIL_MSG("Cannot remove file or directory: " + p_path); + } + } + memdelete(da); + } + virtual String get_filesystem_type() const = 0; static String get_full_path(const String &p_path, AccessType p_access); static DirAccess *create_for_path(const String &p_path); diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 1f6e5bb653..eca5d0567b 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -1955,19 +1955,27 @@ void register_variant_methods() { _VariantCall::add_variant_constant(Variant::VECTOR2, "UP", Vector2(0, -1)); _VariantCall::add_variant_constant(Variant::VECTOR2, "DOWN", Vector2(0, 1)); - _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "IDENTITY", Transform2D(1, 0, 0, 1, 0, 0)); + _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "IDENTITY", Transform2D()); _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_X", Transform2D(-1, 0, 0, 1, 0, 0)); _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_Y", Transform2D(1, 0, 0, -1, 0, 0)); - Transform identity_transform, transform_x, transform_y, transform_z; - identity_transform.set(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0); + Transform identity_transform = Transform(); + Transform flip_x_transform = Transform(-1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0); + Transform flip_y_transform = Transform(1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0); + Transform flip_z_transform = Transform(1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0); _VariantCall::add_variant_constant(Variant::TRANSFORM, "IDENTITY", identity_transform); - transform_x.set(-1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0); - _VariantCall::add_variant_constant(Variant::TRANSFORM, "FLIP_X", transform_x); - transform_y.set(1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0); - _VariantCall::add_variant_constant(Variant::TRANSFORM, "FLIP_Y", transform_y); - transform_z.set(1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0); - _VariantCall::add_variant_constant(Variant::TRANSFORM, "FLIP_Z", transform_z); + _VariantCall::add_variant_constant(Variant::TRANSFORM, "FLIP_X", flip_x_transform); + _VariantCall::add_variant_constant(Variant::TRANSFORM, "FLIP_Y", flip_y_transform); + _VariantCall::add_variant_constant(Variant::TRANSFORM, "FLIP_Z", flip_z_transform); + + Basis identity_basis = Basis(); + Basis flip_x_basis = Basis(-1, 0, 0, 0, 1, 0, 0, 0, 1); + Basis flip_y_basis = Basis(1, 0, 0, 0, -1, 0, 0, 0, 1); + Basis flip_z_basis = Basis(1, 0, 0, 0, 1, 0, 0, 0, -1); + _VariantCall::add_variant_constant(Variant::BASIS, "IDENTITY", identity_basis); + _VariantCall::add_variant_constant(Variant::BASIS, "FLIP_X", flip_x_basis); + _VariantCall::add_variant_constant(Variant::BASIS, "FLIP_Y", flip_y_basis); + _VariantCall::add_variant_constant(Variant::BASIS, "FLIP_Z", flip_z_basis); _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_YZ", Plane(Vector3(1, 0, 0), 0)); _VariantCall::add_variant_constant(Variant::PLANE, "PLANE_XZ", Plane(Vector3(0, 1, 0), 0)); diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 0428140908..b25de3cf99 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -1317,10 +1317,10 @@ No hint for the edited property. </constant> <constant name="PROPERTY_HINT_RANGE" value="1" enum="PropertyHint"> - Hints that an integer or float property should be within a range specified via the hint string [code]"min,max"[/code] or [code]"min,max,step"[/code]. The hint string can optionally include [code]"allow_greater"[/code] and/or [code]"allow_lesser"[/code] to allow manual input going respectively above the max or below the min values. Example: [code]"-360,360,1,allow_greater,allow_lesser"[/code]. + Hints that an integer or float property should be within a range specified via the hint string [code]"min,max"[/code] or [code]"min,max,step"[/code]. The hint string can optionally include [code]"or_greater"[/code] and/or [code]"or_lesser"[/code] to allow manual input going respectively above the max or below the min values. Example: [code]"-360,360,1,or_greater,or_lesser"[/code]. </constant> <constant name="PROPERTY_HINT_EXP_RANGE" value="2" enum="PropertyHint"> - Hints that an integer or float property should be within an exponential range specified via the hint string [code]"min,max"[/code] or [code]"min,max,step"[/code]. The hint string can optionally include [code]"allow_greater"[/code] and/or [code]"allow_lesser"[/code] to allow manual input going respectively above the max or below the min values. Example: [code]"0.01,100,0.01,allow_greater"[/code]. + Hints that an integer or float property should be within an exponential range specified via the hint string [code]"min,max"[/code] or [code]"min,max,step"[/code]. The hint string can optionally include [code]"or_greater"[/code] and/or [code]"or_lesser"[/code] to allow manual input going respectively above the max or below the min values. Example: [code]"0.01,100,0.01,or_greater"[/code]. </constant> <constant name="PROPERTY_HINT_ENUM" value="3" enum="PropertyHint"> Hints that an integer, float or string property is an enumerated value to pick in a list specified via a hint string such as [code]"Hello,Something,Else"[/code]. diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp index 8a177e32b0..4716b29e03 100644 --- a/drivers/gles2/rasterizer_canvas_gles2.cpp +++ b/drivers/gles2/rasterizer_canvas_gles2.cpp @@ -1650,6 +1650,7 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons //always re-set uniforms, since light parameters changed _set_uniforms(); + state.canvas_shader.use_material((void *)material_ptr); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4); RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(light->texture); diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index a0188da4f6..a30af87516 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -5691,21 +5691,49 @@ void RasterizerStorageGLES2::initialize() { GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + glBindFramebuffer(GL_FRAMEBUFFER, system_fbo); + glDeleteFramebuffers(1, &fbo); + glBindTexture(GL_TEXTURE_2D, 0); + glDeleteTextures(1, &depth); + if (status == GL_FRAMEBUFFER_COMPLETE) { config.depth_internalformat = GL_DEPTH_COMPONENT; config.depth_type = GL_UNSIGNED_INT; } else { + // If it fails, test to see if it supports a framebuffer texture using UNSIGNED_SHORT + // This is needed because many OSX devices don't support either UNSIGNED_INT or UNSIGNED_SHORT + config.depth_internalformat = GL_DEPTH_COMPONENT16; config.depth_type = GL_UNSIGNED_SHORT; - } - glBindFramebuffer(GL_FRAMEBUFFER, system_fbo); - glDeleteFramebuffers(1, &fbo); - glBindTexture(GL_TEXTURE_2D, 0); - glDeleteTextures(1, &depth); + glGenFramebuffers(1, &fbo); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + glGenTextures(1, &depth); + glBindTexture(GL_TEXTURE_2D, depth); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, 32, 32, 0, GL_DEPTH_COMPONENT16, GL_UNSIGNED_SHORT, NULL); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth, 0); + + status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + //if it fails again depth textures aren't supported, use rgba shadows and renderbuffer for depth + config.support_depth_texture = false; + config.use_rgba_3d_shadows = true; + } + + glBindFramebuffer(GL_FRAMEBUFFER, system_fbo); + glDeleteFramebuffers(1, &fbo); + glBindTexture(GL_TEXTURE_2D, 0); + glDeleteTextures(1, &depth); + } } else { - // Will use renderbuffer for depth + // Will use renderbuffer for depth, on mobile check for 24 bit depth support if (config.extensions.has("GL_OES_depth24")) { config.depth_internalformat = _DEPTH_COMPONENT24_OES; config.depth_type = GL_UNSIGNED_INT; diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index f4faed8736..1a97225e6b 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -200,6 +200,8 @@ void RasterizerCanvasGLES3::canvas_end() { glBindBufferBase(GL_UNIFORM_BUFFER, 0, 0); glColorMask(1, 1, 1, 1); + glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); + state.using_texture_rect = false; state.using_ninepatch = false; } diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index ed262d9c4f..e1f2635275 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -35,6 +35,7 @@ #include "core/io/resource_saver.h" #include "core/io/zip_io.h" #include "core/math/crypto_core.h" +#include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/project_settings.h" #include "core/script_language.h" @@ -884,6 +885,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & String engine_cfb = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp" + config_file); ProjectSettings::get_singleton()->save_custom(engine_cfb, custom_map, custom_list); Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb); + DirAccess::remove_file_or_error(engine_cfb); p_func(p_udata, "res://" + config_file, data, idx, total); @@ -916,8 +918,10 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c memdelete(ftmp); //close tmp file - if (err) + if (err != OK) { + DirAccess::remove_file_or_error(tmppath); return err; + } pd.file_ofs.sort(); //do sort, so we can do binary search later @@ -926,11 +930,17 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c if (!p_embed) { // Regular output to separate PCK file f = FileAccess::open(p_path, FileAccess::WRITE); - ERR_FAIL_COND_V(!f, ERR_CANT_CREATE); + if (!f) { + DirAccess::remove_file_or_error(tmppath); + ERR_FAIL_V(ERR_CANT_CREATE); + } } else { // Append to executable f = FileAccess::open(p_path, FileAccess::READ_WRITE); - ERR_FAIL_COND_V(!f, ERR_FILE_CANT_OPEN); + if (!f) { + DirAccess::remove_file_or_error(tmppath); + ERR_FAIL_V(ERR_FILE_CANT_OPEN); + } f->seek_end(); embed_pos = f->get_position(); @@ -995,13 +1005,13 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c f->store_8(0); } - //save the rest of the data + // Save the rest of the data. ftmp = FileAccess::open(tmppath, FileAccess::READ); if (!ftmp) { memdelete(f); - ERR_EXPLAIN("Can't open file to read from path: " + String(tmppath)); - ERR_FAIL_V(ERR_CANT_CREATE); + DirAccess::remove_file_or_error(tmppath); + ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't open file to read from path: " + String(tmppath)); } const int bufsize = 16384; @@ -1035,6 +1045,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c } memdelete(f); + DirAccess::remove_file_or_error(tmppath); return OK; } @@ -1043,8 +1054,6 @@ Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, co EditorProgress ep("savezip", TTR("Packing"), 102, true); - //FileAccess *tmp = FileAccess::open(tmppath,FileAccess::WRITE); - FileAccess *src_f; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io); @@ -1694,11 +1703,18 @@ void EditorExportTextSceneToBinaryPlugin::_export_file(const String &p_path, con bool convert = GLOBAL_GET("editor/convert_text_resources_to_binary_on_export"); if (!convert) return; - String tmp_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("file.res"); + String tmp_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpfile.res"); Error err = ResourceFormatLoaderText::convert_file_to_binary(p_path, tmp_path); - ERR_FAIL_COND(err != OK); + if (err != OK) { + DirAccess::remove_file_or_error(tmp_path); + ERR_FAIL(); + } Vector<uint8_t> data = FileAccess::get_file_as_array(tmp_path); - ERR_FAIL_COND(data.size() == 0); + if (data.size() == 0) { + DirAccess::remove_file_or_error(tmp_path); + ERR_FAIL(); + } + DirAccess::remove_file_or_error(tmp_path); add_file(p_path + ".converted.res", data, true); } diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index d81a1dbd77..7aa24c7476 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -1427,11 +1427,10 @@ void EditorHelp::generate_doc() { void EditorHelp::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_READY: case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - _update_doc(); + _update_doc(); } break; default: break; } @@ -1573,7 +1572,6 @@ void EditorHelpBit::_notification(int p_what) { rich_text->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); } break; - default: break; } } @@ -1603,6 +1601,10 @@ FindBar::FindBar() { search_text->connect("text_changed", this, "_search_text_changed"); search_text->connect("text_entered", this, "_search_text_entered"); + matches_label = memnew(Label); + add_child(matches_label); + matches_label->hide(); + find_prev = memnew(ToolButton); add_child(find_prev); find_prev->set_focus_mode(FOCUS_NONE); @@ -1613,9 +1615,9 @@ FindBar::FindBar() { find_next->set_focus_mode(FOCUS_NONE); find_next->connect("pressed", this, "_search_next"); - error_label = memnew(Label); - add_child(error_label); - error_label->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor")); + Control *space = memnew(Control); + add_child(space); + space->set_custom_minimum_size(Size2(4, 0) * EDSCALE); hide_button = memnew(TextureButton); add_child(hide_button); @@ -1645,25 +1647,21 @@ void FindBar::popup_search() { void FindBar::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - - find_prev->set_icon(get_icon("MoveUp", "EditorIcons")); - find_next->set_icon(get_icon("MoveDown", "EditorIcons")); - hide_button->set_normal_texture(get_icon("Close", "EditorIcons")); - hide_button->set_hover_texture(get_icon("Close", "EditorIcons")); - hide_button->set_pressed_texture(get_icon("Close", "EditorIcons")); - hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); - } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - - set_process_unhandled_input(is_visible_in_tree()); - } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - - find_prev->set_icon(get_icon("MoveUp", "EditorIcons")); - find_next->set_icon(get_icon("MoveDown", "EditorIcons")); - hide_button->set_normal_texture(get_icon("Close", "EditorIcons")); - hide_button->set_hover_texture(get_icon("Close", "EditorIcons")); - hide_button->set_pressed_texture(get_icon("Close", "EditorIcons")); - hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + + find_prev->set_icon(get_icon("MoveUp", "EditorIcons")); + find_next->set_icon(get_icon("MoveDown", "EditorIcons")); + hide_button->set_normal_texture(get_icon("Close", "EditorIcons")); + hide_button->set_hover_texture(get_icon("Close", "EditorIcons")); + hide_button->set_pressed_texture(get_icon("Close", "EditorIcons")); + hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); + } break; + case NOTIFICATION_VISIBILITY_CHANGED: { + + set_process_unhandled_input(is_visible_in_tree()); + } break; } } @@ -1708,17 +1706,52 @@ bool FindBar::_search(bool p_search_previous) { prev_search = stext; if (ret) { - set_error(""); + _update_results_count(); } else { - set_error(stext.empty() ? "" : TTR("No Matches")); + results_count = 0; } + _update_matches_label(); return ret; } -void FindBar::set_error(const String &p_label) { +void FindBar::_update_results_count() { + + results_count = 0; + + String searched = search_text->get_text(); + if (searched.empty()) return; + + String full_text = rich_text_label->get_text(); + + int from_pos = 0; + + while (true) { + int pos = full_text.find(searched, from_pos); + if (pos == -1) + break; + + results_count++; + from_pos = pos + searched.length(); + } +} + +void FindBar::_update_matches_label() { + + if (results_count > 0) { + matches_label->show(); + + matches_label->add_color_override("font_color", Color(1, 1, 1)); + matches_label->set_text(vformat(TTR("Found %d match(es)."), results_count)); + } else if (search_text->get_text().empty()) { - error_label->set_text(p_label); + matches_label->hide(); + } else { + matches_label->show(); + + matches_label->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor")); + matches_label->set_text(TTR("No Matches")); + } } void FindBar::_hide_bar() { diff --git a/editor/editor_help.h b/editor/editor_help.h index a50ab8a9f9..3824ba231e 100644 --- a/editor/editor_help.h +++ b/editor/editor_help.h @@ -49,18 +49,23 @@ class FindBar : public HBoxContainer { LineEdit *search_text; ToolButton *find_prev; ToolButton *find_next; - Label *error_label; + Label *matches_label; TextureButton *hide_button; String prev_search; RichTextLabel *rich_text_label; + int results_count; + void _show_search(); void _hide_bar(); void _search_text_changed(const String &p_text); void _search_text_entered(const String &p_text); + void _update_results_count(); + void _update_matches_label(); + void _update_size(); protected: @@ -72,8 +77,6 @@ protected: static void _bind_methods(); public: - void set_error(const String &p_label); - void set_rich_text_label(RichTextLabel *p_rich_text_label); void popup_search(); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 3300228921..20ba07c102 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -116,7 +116,7 @@ void EditorPropertyMultilineText::_open_big_text() { add_child(big_text_dialog); } - big_text_dialog->popup_centered_ratio(); + big_text_dialog->popup_centered_clamped(Size2(1000, 900) * EDSCALE, 0.8); big_text->set_text(text->get_text()); big_text->grab_focus(); } diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 203136a3f8..d1371a04b1 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -312,7 +312,8 @@ void EditorPropertyArray::update_property() { } else { //bye bye children of the box while (vbox->get_child_count() > 2) { - memdelete(vbox->get_child(2)); + vbox->get_child(2)->queue_delete(); // button still needed after pressed is called + vbox->remove_child(vbox->get_child(2)); } } diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index ecfad4d146..8a5f77c25f 100644 --- a/editor/export_template_manager.cpp +++ b/editor/export_template_manager.cpp @@ -422,14 +422,16 @@ void ExportTemplateManager::_http_download_templates_completed(int p_status, int String path = download_templates->get_download_file(); template_list_state->set_text(TTR("Download Complete.")); template_downloader->hide(); - int ret = _install_from_file(path, false); + bool ret = _install_from_file(path, false); if (ret) { - Error err = OS::get_singleton()->move_to_trash(path); + // Clean up downloaded file. + DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + Error err = da->remove(path); if (err != OK) { - EditorNode::get_singleton()->add_io_error(TTR("Cannot remove:") + "\n" + path + "\n"); + EditorNode::get_singleton()->add_io_error(TTR("Cannot remove temporary file:") + "\n" + path + "\n"); } } else { - WARN_PRINTS(vformat(TTR("Templates installation failed. The problematic templates archives can be found at '%s'."), path)); + EditorNode::get_singleton()->add_io_error(vformat(TTR("Templates installation failed.\nThe problematic templates archives can be found at '%s'."), path)); } } } break; @@ -458,7 +460,7 @@ void ExportTemplateManager::_begin_template_download(const String &p_url) { Error err = download_templates->request(p_url); if (err != OK) { - EditorNode::get_singleton()->show_warning(TTR("Error requesting url: ") + p_url); + EditorNode::get_singleton()->show_warning(TTR("Error requesting URL:") + " " + p_url); return; } diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index 8665467f2d..cc2efb92ae 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -547,6 +547,7 @@ FindInFilesPanel::FindInFilesPanel() { _results_display->connect("item_edited", this, "_on_item_edited"); _results_display->set_hide_root(true); _results_display->set_select_mode(Tree::SELECT_ROW); + _results_display->set_allow_rmb_select(true); _results_display->create_item(); // Root vbc->add_child(_results_display); diff --git a/editor/icons/icon_gizmo_c_p_u_particles.svg b/editor/icons/icon_gizmo_c_p_u_particles.svg new file mode 100644 index 0000000000..a6f0eaef5b --- /dev/null +++ b/editor/icons/icon_gizmo_c_p_u_particles.svg @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="128" + height="128" + version="1.1" + viewBox="0 0 128 128" + id="svg6" + sodipodi:docname="icon_gizmo_c_p_u_particles.svg" + inkscape:version="0.92.4 5da689c313, 2019-01-14"> + <metadata + id="metadata12"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs10" /> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1606" + inkscape:window-height="821" + id="namedview8" + showgrid="false" + inkscape:zoom="2.6074563" + inkscape:cx="101.29539" + inkscape:cy="83.191634" + inkscape:window-x="295" + inkscape:window-y="81" + inkscape:window-maximized="0" + inkscape:current-layer="svg6" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" /> + <path + style="display:inline;opacity:1;fill:#f7f5cf;fill-opacity:1;stroke:#b4b4b4;stroke-width:2.56380486;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m 35.503779,1.2819066 c -3.570424,0 -6.435164,2.9483368 -6.435164,6.6019028 v 4.3900146 c 0,0.889114 0.169457,1.726301 0.478513,2.49893 H 19.465369 c -3.570424,0 -6.435167,2.931453 -6.435167,6.585021 v 7.969562 c -0.341543,-0.0568 -0.648813,-0.202614 -1.006525,-0.202614 H 7.7335674 c -3.5704232,0 -6.451665,2.948338 -6.451665,6.601904 v 3.224972 c 0,3.653568 2.8812418,6.585016 6.451665,6.585016 h 4.2901096 c 0.358169,0 0.664563,-0.14568 1.006525,-0.202618 V 83.83104 C 12.688659,83.77398 12.381388,83.628424 12.023677,83.628424 H 7.7335674 c -3.5704232,0 -6.451665,2.948332 -6.451665,6.601908 v 3.224971 c 0,3.653575 2.8812418,6.585017 6.451665,6.585017 h 4.2901096 c 0.358169,0 0.664563,-0.145692 1.006525,-0.202612 v 9.725542 c 0,3.6536 2.864743,6.60193 6.435167,6.60193 h 9.603246 v 3.951 c 0,3.65357 2.86474,6.60192 6.435164,6.60192 h 3.15158 c 3.57042,0 6.451663,-2.94836 6.451663,-6.60192 v -3.95104 h 37.224955 v 3.951 c 0,3.65358 2.86474,6.60193 6.435166,6.60193 h 3.151583 c 3.570418,0 6.451653,-2.94836 6.451653,-6.60193 v -3.951 h 10.725281 c 3.57043,0 6.45166,-2.94833 6.45166,-6.60191 v -9.607372 c 0.14985,0.0105 0.27643,0.0846 0.42899,0.0846 h 4.29014 c 3.5704,0 6.45165,-2.931432 6.45165,-6.585011 v -3.224992 c 0,-3.653565 -2.88125,-6.601906 -6.45165,-6.601906 h -4.29014 c -0.15231,0 -0.27938,0.07348 -0.42899,0.08472 V 45.452198 c 0.14985,0.01042 0.27643,0.08445 0.42899,0.08445 h 4.29014 c 3.5704,0 6.45165,-2.931451 6.45165,-6.585023 v -3.224986 c 0,-3.653566 -2.88125,-6.601906 -6.45165,-6.601906 h -4.29014 c -0.15231,0 -0.27938,0.07392 -0.42899,0.08446 v -7.851429 c 0,-3.653567 -2.88123,-6.585019 -6.45166,-6.585021 H 97.875379 c 0.309043,-0.772641 0.494982,-1.609791 0.494982,-2.498929 V 7.8838054 c 0,-3.6535651 -2.881246,-6.601903 -6.451662,-6.601903 h -3.15158 c -3.570428,0 -6.435167,2.9483379 -6.435167,6.601903 V 12.27382 c 0,0.889115 0.16948,1.726301 0.478507,2.49893 H 44.612011 c 0.309083,-0.772642 0.495011,-1.609792 0.495011,-2.49893 V 7.8838054 c 0,-3.6535651 -2.881243,-6.601903 -6.451663,-6.601903 z" + id="path4542" + inkscape:connector-curvature="0" /> + <path + style="opacity:1;fill:#b4b4b4;fill-opacity:1;stroke-width:8.54601765" + d="M 62.861474,21.661698 A 27.707285,31.502779 0 0 1 90.004671,47.07312 18.471523,18.901669 0 0 1 105.96058,65.764449 18.471523,18.901669 0 0 1 87.480108,84.658396 H 38.226348 A 18.471523,18.901669 0 0 1 19.762375,65.764449 18.471523,18.901669 0 0 1 35.685283,47.056234 27.707285,31.502779 0 0 1 62.861474,21.661698 Z" + id="path4540" + inkscape:connector-curvature="0" /> + <path + style="opacity:1;fill:#b4b4b4;fill-opacity:1;stroke-width:8.54601765" + d="m 38.226348,90.956369 a 6.1571744,6.3005562 0 0 1 6.154657,6.297979 6.1571744,6.3005562 0 0 1 -6.154657,6.314882 6.1571744,6.3005562 0 0 1 -6.154657,-6.314882 6.1571744,6.3005562 0 0 1 6.154657,-6.297979 z" + id="path4538" + inkscape:connector-curvature="0" /> + <path + style="opacity:1;fill:#b4b4b4;fill-opacity:1;stroke-width:8.54601765" + d="m 87.480108,90.956369 a 6.1571744,6.3005562 0 0 1 6.171159,6.297979 6.1571744,6.3005562 0 0 1 -6.171159,6.314882 6.1571744,6.3005562 0 0 1 -6.154656,-6.314882 6.1571744,6.3005562 0 0 1 6.154656,-6.297979 z" + id="path4536" + inkscape:connector-curvature="0" /> + <path + style="opacity:1;fill:#b4b4b4;fill-opacity:1;stroke-width:8.54601765" + d="m 62.861474,97.254348 a 6.1571744,6.3005562 0 0 1 6.154662,6.314882 6.1571744,6.3005562 0 0 1 -6.154662,6.29797 6.1571744,6.3005562 0 0 1 -6.154651,-6.29797 6.1571744,6.3005562 0 0 1 6.154651,-6.314882 z" + id="rect822" + inkscape:connector-curvature="0" /> + <g + inkscape:groupmode="layer" + id="layer1" + inkscape:label="Layer 1" + transform="translate(-0.35794507,-5.5049216)" /> +</svg> diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index b5231ce468..5679426eb5 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -354,16 +354,16 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int } break; case HTTPRequest::RESULT_REQUEST_FAILED: { error_text = TTR("Request failed, return code:") + " " + itos(p_code); - status->set_text(TTR("Request Failed.")); + status->set_text(TTR("Request failed.")); } break; case HTTPRequest::RESULT_DOWNLOAD_FILE_CANT_OPEN: case HTTPRequest::RESULT_DOWNLOAD_FILE_WRITE_ERROR: { - error_text = TTR("Cannot save response to") + " " + download->get_download_file(); + error_text = TTR("Cannot save response to:") + " " + download->get_download_file(); status->set_text(TTR("Write error.")); } break; case HTTPRequest::RESULT_REDIRECT_LIMIT_REACHED: { error_text = TTR("Request failed, too many redirects"); - status->set_text(TTR("Redirect Loop.")); + status->set_text(TTR("Redirect loop.")); } break; case HTTPRequest::RESULT_TIMEOUT: { error_text = TTR("Request failed, timeout"); @@ -407,8 +407,6 @@ void EditorAssetLibraryItemDownload::configure(const String &p_title, int p_asse icon->set_texture(get_icon("DefaultProjectIcon", "EditorIcons")); host = p_download_url; sha256 = p_sha256_hash; - asset_installer->connect("confirmed", this, "_close"); - dismiss->set_normal_texture(get_icon("Close", "EditorIcons")); _make_request(); } @@ -416,9 +414,11 @@ void EditorAssetLibraryItemDownload::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_READY: { + // FIXME: The editor crashes if 'NOTICATION_THEME_CHANGED' is used. + case NOTIFICATION_ENTER_TREE: { add_style_override("panel", get_stylebox("panel", "TabContainer")); + dismiss->set_normal_texture(get_icon("Close", "EditorIcons")); } break; case NOTIFICATION_PROCESS: { @@ -472,9 +472,8 @@ void EditorAssetLibraryItemDownload::_notification(int p_what) { } void EditorAssetLibraryItemDownload::_close() { - DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - da->remove(download->get_download_file()); //clean up removed file - memdelete(da); + // Clean up downloaded file. + DirAccess::remove_file_or_error(download->get_download_file()); queue_delete(); } @@ -571,6 +570,7 @@ EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { asset_installer = memnew(EditorAssetInstaller); add_child(asset_installer); + asset_installer->connect("confirmed", this, "_close"); prev_status = -1; diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index becf60bf28..ec391186c3 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -56,7 +56,7 @@ void ScriptEditorBase::_bind_methods() { ADD_SIGNAL(MethodInfo("request_open_script_at_line", PropertyInfo(Variant::OBJECT, "script"), PropertyInfo(Variant::INT, "line"))); ADD_SIGNAL(MethodInfo("request_save_history")); ADD_SIGNAL(MethodInfo("go_to_help", PropertyInfo(Variant::STRING, "what"))); - // TODO This signal is no use for VisualScript... + // TODO: This signal is no use for VisualScript. ADD_SIGNAL(MethodInfo("search_in_files_requested", PropertyInfo(Variant::STRING, "text"))); } @@ -205,11 +205,13 @@ void ScriptEditorQuickOpen::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - connect("confirmed", this, "_confirmed"); - search_box->set_right_icon(get_icon("Search", "EditorIcons")); search_box->set_clear_button_enabled(true); + FALLTHROUGH; + } + case NOTIFICATION_THEME_CHANGED: { + search_box->set_right_icon(get_icon("Search", "EditorIcons")); } break; case NOTIFICATION_EXIT_TREE: { disconnect("confirmed", this, "_confirmed"); @@ -242,6 +244,8 @@ ScriptEditorQuickOpen::ScriptEditorQuickOpen() { set_hide_on_ok(false); search_options->connect("item_activated", this, "_confirmed"); search_options->set_hide_root(true); + search_options->set_hide_folding(true); + search_options->add_constant_override("draw_guides", 1); } ///////////////////////////////// diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index cc323c7e0a..98e0edd581 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -30,6 +30,7 @@ #include "script_text_editor.h" +#include "core/math/expression.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" @@ -1147,6 +1148,32 @@ void ScriptTextEditor::_edit_option(int p_op) { _convert_case(CodeTextEditor::CAPITALIZE); } break; + case EDIT_EVALUATE: { + + Expression expression; + Vector<String> lines = code_editor->get_text_edit()->get_selection_text().split("\n"); + PoolStringArray results; + + for (int i = 0; i < lines.size(); i++) { + String line = lines[i]; + String whitespace = line.substr(0, line.size() - line.strip_edges(true, false).size()); //extract the whitespace at the beginning + + if (expression.parse(line) == OK) { + Variant result = expression.execute(Array(), Variant(), false); + if (expression.get_error_text() == "") { + results.append(whitespace + (String)result); + } else { + results.append(line); + } + } else { + results.append(line); + } + } + + code_editor->get_text_edit()->begin_complex_operation(); //prevents creating a two-step undo + code_editor->get_text_edit()->insert_text_at_cursor(results.join("\n")); + code_editor->get_text_edit()->end_complex_operation(); + } break; case SEARCH_FIND: { code_editor->get_find_replace_bar()->popup_search(); @@ -1621,7 +1648,9 @@ void ScriptTextEditor::_color_changed(const Color &p_color) { line_with_replaced_args = line_with_replaced_args.insert(color_args_pos, new_args); color_args = new_args; + code_editor->get_text_edit()->begin_complex_operation(); code_editor->get_text_edit()->set_line(color_position.x, line_with_replaced_args); + code_editor->get_text_edit()->end_complex_operation(); code_editor->get_text_edit()->update(); } @@ -1648,6 +1677,7 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p context_menu->add_separator(); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_uppercase"), EDIT_TO_UPPERCASE); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE); } if (p_foldable) context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE); @@ -1748,6 +1778,7 @@ ScriptTextEditor::ScriptTextEditor() { edit_menu->get_popup()->add_separator(); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_spaces"), EDIT_CONVERT_INDENT_TO_SPACES); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_tabs"), EDIT_CONVERT_INDENT_TO_TABS); @@ -1784,11 +1815,7 @@ ScriptTextEditor::ScriptTextEditor() { search_menu->get_popup()->add_separator(); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_in_files"), SEARCH_IN_FILES); search_menu->get_popup()->add_separator(); - search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_function"), SEARCH_LOCATE_FUNCTION); - search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); - search_menu->get_popup()->add_separator(); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/contextual_help"), HELP_CONTEXTUAL); - search_menu->get_popup()->connect("id_pressed", this, "_edit_option"); edit_hb->add_child(edit_menu); @@ -1797,6 +1824,11 @@ ScriptTextEditor::ScriptTextEditor() { edit_hb->add_child(goto_menu); goto_menu->set_text(TTR("Go To")); goto_menu->set_switch_on_hover(true); + goto_menu->get_popup()->connect("id_pressed", this, "_edit_option"); + + goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_function"), SEARCH_LOCATE_FUNCTION); + goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); + goto_menu->get_popup()->add_separator(); bookmarks_menu = memnew(PopupMenu); bookmarks_menu->set_name("Bookmarks"); @@ -1856,16 +1888,12 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/move_down", TTR("Move Down"), KEY_MASK_ALT | KEY_DOWN); ED_SHORTCUT("script_text_editor/delete_line", TTR("Delete Line"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_K); - //leave these at zero, same can be accomplished with tab/shift-tab, including selection - //the next/previous in history shortcut in this case makes a lot more sene. + // Leave these at zero, same can be accomplished with tab/shift-tab, including selection. + // The next/previous in history shortcut in this case makes a lot more sense. ED_SHORTCUT("script_text_editor/indent_left", TTR("Indent Left"), 0); ED_SHORTCUT("script_text_editor/indent_right", TTR("Indent Right"), 0); ED_SHORTCUT("script_text_editor/toggle_comment", TTR("Toggle Comment"), KEY_MASK_CMD | KEY_K); - ED_SHORTCUT("script_text_editor/toggle_bookmark", TTR("Toggle Bookmark"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_B); - ED_SHORTCUT("script_text_editor/goto_next_bookmark", TTR("Go to Next Bookmark"), KEY_MASK_CMD | KEY_B); - ED_SHORTCUT("script_text_editor/goto_previous_bookmark", TTR("Go to Previous Bookmark"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B); - ED_SHORTCUT("script_text_editor/remove_all_bookmarks", TTR("Remove All Bookmarks"), 0); ED_SHORTCUT("script_text_editor/toggle_fold_line", TTR("Fold/Unfold Line"), KEY_MASK_ALT | KEY_F); ED_SHORTCUT("script_text_editor/fold_all_lines", TTR("Fold All Lines"), 0); ED_SHORTCUT("script_text_editor/unfold_all_lines", TTR("Unfold All Lines"), 0); @@ -1876,20 +1904,12 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_CMD | KEY_D); ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CMD | KEY_SPACE); #endif + ED_SHORTCUT("script_text_editor/evaluate_selection", TTR("Evaluate Selection"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_E); ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_T); ED_SHORTCUT("script_text_editor/convert_indent_to_spaces", TTR("Convert Indent to Spaces"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_Y); ED_SHORTCUT("script_text_editor/convert_indent_to_tabs", TTR("Convert Indent to Tabs"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_I); ED_SHORTCUT("script_text_editor/auto_indent", TTR("Auto Indent"), KEY_MASK_CMD | KEY_I); -#ifdef OSX_ENABLED - ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B); -#else - ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9); -#endif - ED_SHORTCUT("script_text_editor/remove_all_breakpoints", TTR("Remove All Breakpoints"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F9); - ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Go to Next Breakpoint"), KEY_MASK_CMD | KEY_PERIOD); - ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Go to Previous Breakpoint"), KEY_MASK_CMD | KEY_COMMA); - ED_SHORTCUT("script_text_editor/find", TTR("Find..."), KEY_MASK_CMD | KEY_F); #ifdef OSX_ENABLED ED_SHORTCUT("script_text_editor/find_next", TTR("Find Next"), KEY_MASK_CMD | KEY_G); @@ -1904,6 +1924,17 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/find_in_files", TTR("Find in Files..."), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F); #ifdef OSX_ENABLED + ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_MASK_SHIFT | KEY_SPACE); +#else + ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_F1); +#endif + + ED_SHORTCUT("script_text_editor/toggle_bookmark", TTR("Toggle Bookmark"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_B); + ED_SHORTCUT("script_text_editor/goto_next_bookmark", TTR("Go to Next Bookmark"), KEY_MASK_CMD | KEY_B); + ED_SHORTCUT("script_text_editor/goto_previous_bookmark", TTR("Go to Previous Bookmark"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B); + ED_SHORTCUT("script_text_editor/remove_all_bookmarks", TTR("Remove All Bookmarks"), 0); + +#ifdef OSX_ENABLED ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KEY_MASK_CTRL | KEY_MASK_CMD | KEY_J); #else ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KEY_MASK_ALT | KEY_MASK_CMD | KEY_F); @@ -1911,10 +1942,13 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/goto_line", TTR("Go to Line..."), KEY_MASK_CMD | KEY_L); #ifdef OSX_ENABLED - ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_MASK_SHIFT | KEY_SPACE); + ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B); #else - ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_F1); + ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9); #endif + ED_SHORTCUT("script_text_editor/remove_all_breakpoints", TTR("Remove All Breakpoints"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F9); + ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Go to Next Breakpoint"), KEY_MASK_CMD | KEY_PERIOD); + ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Go to Previous Breakpoint"), KEY_MASK_CMD | KEY_COMMA); ScriptEditor::register_create_script_editor_function(create_editor); } diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index 4b2307555b..38c6da5c33 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -120,6 +120,7 @@ class ScriptTextEditor : public ScriptEditorBase { EDIT_TO_UPPERCASE, EDIT_TO_LOWERCASE, EDIT_CAPITALIZE, + EDIT_EVALUATE, EDIT_TOGGLE_FOLD_LINE, EDIT_FOLD_ALL_LINES, EDIT_UNFOLD_ALL_LINES, diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 37460c58ff..04820b8a8f 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -529,19 +529,19 @@ void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { void ShaderEditor::_update_bookmark_list() { - bookmarks_menu->get_popup()->clear(); + bookmarks_menu->clear(); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV); Array bookmark_list = shader_editor->get_text_edit()->get_bookmarks_array(); if (bookmark_list.size() == 0) { return; } - bookmarks_menu->get_popup()->add_separator(); + bookmarks_menu->add_separator(); for (int i = 0; i < bookmark_list.size(); i++) { String line = shader_editor->get_text_edit()->get_line(bookmark_list[i]).strip_edges(); @@ -550,17 +550,17 @@ void ShaderEditor::_update_bookmark_list() { line = line.substr(0, 50); } - bookmarks_menu->get_popup()->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); - bookmarks_menu->get_popup()->set_item_metadata(bookmarks_menu->get_popup()->get_item_count() - 1, bookmark_list[i]); + bookmarks_menu->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); + bookmarks_menu->set_item_metadata(bookmarks_menu->get_item_count() - 1, bookmark_list[i]); } } void ShaderEditor::_bookmark_item_pressed(int p_idx) { if (p_idx < 4) { // Any item before the separator. - _menu_option(bookmarks_menu->get_popup()->get_item_id(p_idx)); + _menu_option(bookmarks_menu->get_item_id(p_idx)); } else { - shader_editor->goto_line(bookmarks_menu->get_popup()->get_item_metadata(p_idx)); + shader_editor->goto_line(bookmarks_menu->get_item_metadata(p_idx)); } } @@ -649,16 +649,23 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE); - search_menu->get_popup()->add_separator(); - search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); search_menu->get_popup()->connect("id_pressed", this, "_menu_option"); - bookmarks_menu = memnew(MenuButton); - bookmarks_menu->set_text(TTR("Bookmarks")); - bookmarks_menu->set_switch_on_hover(true); + MenuButton *goto_menu = memnew(MenuButton); + goto_menu->set_text(TTR("Go To")); + goto_menu->set_switch_on_hover(true); + goto_menu->get_popup()->connect("id_pressed", this, "_menu_option"); + + goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); + goto_menu->get_popup()->add_separator(); + + bookmarks_menu = memnew(PopupMenu); + bookmarks_menu->set_name("Bookmarks"); + goto_menu->get_popup()->add_child(bookmarks_menu); + goto_menu->get_popup()->add_submenu_item(TTR("Bookmarks"), "Bookmarks"); _update_bookmark_list(); bookmarks_menu->connect("about_to_show", this, "_update_bookmark_list"); - bookmarks_menu->get_popup()->connect("index_pressed", this, "_bookmark_item_pressed"); + bookmarks_menu->connect("index_pressed", this, "_bookmark_item_pressed"); help_menu = memnew(MenuButton); help_menu->set_text(TTR("Help")); @@ -670,7 +677,7 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { main_container->add_child(hbc); hbc->add_child(search_menu); hbc->add_child(edit_menu); - hbc->add_child(bookmarks_menu); + hbc->add_child(goto_menu); hbc->add_child(help_menu); hbc->add_style_override("panel", p_node->get_gui_base()->get_stylebox("ScriptEditorPanel", "EditorStyles")); main_container->add_child(shader_editor); diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h index 5d03c37dc4..8d3f4d4fe8 100644 --- a/editor/plugins/shader_editor_plugin.h +++ b/editor/plugins/shader_editor_plugin.h @@ -99,7 +99,7 @@ class ShaderEditor : public PanelContainer { MenuButton *edit_menu; MenuButton *search_menu; - MenuButton *bookmarks_menu; + PopupMenu *bookmarks_menu; MenuButton *help_menu; PopupMenu *context_menu; uint64_t idle; diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index d2b1cfc5af..58234ba954 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -5438,6 +5438,7 @@ void SpatialEditor::_register_all_gizmos() { add_gizmo_plugin(Ref<VehicleWheelSpatialGizmoPlugin>(memnew(VehicleWheelSpatialGizmoPlugin))); add_gizmo_plugin(Ref<VisibilityNotifierGizmoPlugin>(memnew(VisibilityNotifierGizmoPlugin))); add_gizmo_plugin(Ref<ParticlesGizmoPlugin>(memnew(ParticlesGizmoPlugin))); + add_gizmo_plugin(Ref<CPUParticlesGizmoPlugin>(memnew(CPUParticlesGizmoPlugin))); add_gizmo_plugin(Ref<ReflectionProbeGizmoPlugin>(memnew(ReflectionProbeGizmoPlugin))); add_gizmo_plugin(Ref<GIProbeGizmoPlugin>(memnew(GIProbeGizmoPlugin))); add_gizmo_plugin(Ref<BakedIndirectLightGizmoPlugin>(memnew(BakedIndirectLightGizmoPlugin))); diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index a8fbadb773..eb0794ba77 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -221,19 +221,19 @@ void TextEditor::_validate_script() { void TextEditor::_update_bookmark_list() { - bookmarks_menu->get_popup()->clear(); + bookmarks_menu->clear(); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV); Array bookmark_list = code_editor->get_text_edit()->get_bookmarks_array(); if (bookmark_list.size() == 0) { return; } - bookmarks_menu->get_popup()->add_separator(); + bookmarks_menu->add_separator(); for (int i = 0; i < bookmark_list.size(); i++) { String line = code_editor->get_text_edit()->get_line(bookmark_list[i]).strip_edges(); @@ -242,17 +242,17 @@ void TextEditor::_update_bookmark_list() { line = line.substr(0, 50); } - bookmarks_menu->get_popup()->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); - bookmarks_menu->get_popup()->set_item_metadata(bookmarks_menu->get_popup()->get_item_count() - 1, bookmark_list[i]); + bookmarks_menu->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); + bookmarks_menu->set_item_metadata(bookmarks_menu->get_item_count() - 1, bookmark_list[i]); } } void TextEditor::_bookmark_item_pressed(int p_idx) { if (p_idx < 4) { // Any item before the separator. - _edit_option(bookmarks_menu->get_popup()->get_item_id(p_idx)); + _edit_option(bookmarks_menu->get_item_id(p_idx)); } else { - code_editor->goto_line(bookmarks_menu->get_popup()->get_item_metadata(p_idx)); + code_editor->goto_line(bookmarks_menu->get_item_metadata(p_idx)); } } @@ -636,11 +636,6 @@ TextEditor::TextEditor() { search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE); - search_menu->get_popup()->add_separator(); - search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); - - goto_line_dialog = memnew(GotoLineDialog); - add_child(goto_line_dialog); edit_menu = memnew(MenuButton); edit_menu->set_text(TTR("Edit")); @@ -689,13 +684,25 @@ TextEditor::TextEditor() { highlighter_menu->add_radio_check_item(TTR("Standard")); highlighter_menu->connect("id_pressed", this, "_change_syntax_highlighter"); - bookmarks_menu = memnew(MenuButton); - edit_hb->add_child(bookmarks_menu); - bookmarks_menu->set_text(TTR("Bookmarks")); - bookmarks_menu->set_switch_on_hover(true); + MenuButton *goto_menu = memnew(MenuButton); + edit_hb->add_child(goto_menu); + goto_menu->set_text(TTR("Go To")); + goto_menu->set_switch_on_hover(true); + goto_menu->get_popup()->connect("id_pressed", this, "_edit_option"); + + goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); + goto_menu->get_popup()->add_separator(); + + bookmarks_menu = memnew(PopupMenu); + bookmarks_menu->set_name(TTR("Bookmarks")); + goto_menu->get_popup()->add_child(bookmarks_menu); + goto_menu->get_popup()->add_submenu_item(TTR("Bookmarks"), "Bookmarks"); _update_bookmark_list(); bookmarks_menu->connect("about_to_show", this, "_update_bookmark_list"); - bookmarks_menu->get_popup()->connect("index_pressed", this, "_bookmark_item_pressed"); + bookmarks_menu->connect("index_pressed", this, "_bookmark_item_pressed"); + + goto_line_dialog = memnew(GotoLineDialog); + add_child(goto_line_dialog); code_editor->get_text_edit()->set_drag_forwarding(this); } diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h index c0d4052646..c69e1672c5 100644 --- a/editor/plugins/text_editor.h +++ b/editor/plugins/text_editor.h @@ -46,7 +46,7 @@ private: MenuButton *edit_menu; PopupMenu *highlighter_menu; MenuButton *search_menu; - MenuButton *bookmarks_menu; + PopupMenu *bookmarks_menu; PopupMenu *context_menu; GotoLineDialog *goto_line_dialog; diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 5b67d259ba..873b125200 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -631,14 +631,12 @@ ThemeEditor::ThemeEditor() { scroll = memnew(ScrollContainer); add_child(scroll); - scroll->set_theme(Theme::get_default()); scroll->set_enable_v_scroll(true); scroll->set_enable_h_scroll(false); scroll->set_v_size_flags(SIZE_EXPAND_FILL); main_container = memnew(MarginContainer); scroll->add_child(main_container); - main_container->set_theme(Theme::get_default()); main_container->set_clip_contents(true); main_container->set_custom_minimum_size(Size2(700, 0) * EDSCALE); main_container->set_v_size_flags(SIZE_EXPAND_FILL); @@ -648,9 +646,11 @@ ThemeEditor::ThemeEditor() { Panel *panel = memnew(Panel); main_container->add_child(panel); + panel->set_theme(Theme::get_default()); MarginContainer *mc = memnew(MarginContainer); main_container->add_child(mc); + mc->set_theme(Theme::get_default()); mc->add_constant_override("margin_right", 4 * EDSCALE); mc->add_constant_override("margin_top", 4 * EDSCALE); mc->add_constant_override("margin_left", 4 * EDSCALE); @@ -695,19 +695,19 @@ ThemeEditor::ThemeEditor() { test_menu_button->get_popup()->add_separator(); test_menu_button->get_popup()->add_check_item(TTR("Check Item")); test_menu_button->get_popup()->add_check_item(TTR("Checked Item")); - test_menu_button->get_popup()->set_item_checked(3, true); + test_menu_button->get_popup()->set_item_checked(4, true); test_menu_button->get_popup()->add_separator(); test_menu_button->get_popup()->add_radio_check_item(TTR("Radio Item")); test_menu_button->get_popup()->add_radio_check_item(TTR("Checked Radio Item")); - test_menu_button->get_popup()->set_item_checked(6, true); + test_menu_button->get_popup()->set_item_checked(7, true); test_menu_button->get_popup()->add_separator(TTR("Named Sep.")); PopupMenu *test_submenu = memnew(PopupMenu); test_menu_button->get_popup()->add_child(test_submenu); test_submenu->set_name("submenu"); test_menu_button->get_popup()->add_submenu_item(TTR("Submenu"), "submenu"); - test_submenu->add_item(TTR("Item 1")); - test_submenu->add_item(TTR("Item 2")); + test_submenu->add_item(TTR("Subitem 1")); + test_submenu->add_item(TTR("Subitem 2")); first_vb->add_child(test_menu_button); OptionButton *test_option_button = memnew(OptionButton); diff --git a/editor/pvrtc_compress.cpp b/editor/pvrtc_compress.cpp index 84cd6da3d9..7cdd900d25 100644 --- a/editor/pvrtc_compress.cpp +++ b/editor/pvrtc_compress.cpp @@ -32,6 +32,7 @@ #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" +#include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/os/os.h" #include "editor_settings.h" @@ -52,57 +53,75 @@ static void _compress_image(Image::CompressMode p_mode, Image *p_image) { _base_image_compress_pvrtc2_func(p_image); else if (_base_image_compress_pvrtc4_func) _base_image_compress_pvrtc4_func(p_image); - break; case Image::COMPRESS_PVRTC4: if (_base_image_compress_pvrtc4_func) _base_image_compress_pvrtc4_func(p_image); - break; - default: ERR_FAIL(); + default: + ERR_FAIL_MSG("Unsupported Image compress mode used in PVRTC module."); } return; } - String tmppath = EditorSettings::get_singleton()->get_cache_dir(); - - List<String> args; + String tmppath = EditorSettings::get_singleton()->get_cache_dir(); String src_img = tmppath.plus_file("_tmp_src_img.png"); String dst_img = tmppath.plus_file("_tmp_dst_img.pvr"); + List<String> args; args.push_back("-i"); args.push_back(src_img); args.push_back("-o"); args.push_back(dst_img); args.push_back("-f"); - switch (p_mode) { - case Image::COMPRESS_PVRTC2: args.push_back("PVRTC2"); break; - case Image::COMPRESS_PVRTC4: args.push_back("PVRTC4"); break; - case Image::COMPRESS_ETC: args.push_back("ETC"); break; - default: ERR_FAIL(); + switch (p_mode) { + case Image::COMPRESS_PVRTC2: + args.push_back("PVRTC2"); + break; + case Image::COMPRESS_PVRTC4: + args.push_back("PVRTC4"); + break; + case Image::COMPRESS_ETC: + args.push_back("ETC"); + break; + default: + ERR_FAIL_MSG("Unsupported Image compress mode used in PVRTC module."); } if (EditorSettings::get_singleton()->get("filesystem/import/pvrtc_fast_conversion").operator bool()) { args.push_back("-pvrtcfast"); } - if (p_image->has_mipmaps()) + if (p_image->has_mipmaps()) { args.push_back("-m"); + } + // Save source PNG. Ref<ImageTexture> t = memnew(ImageTexture); t->create_from_image(Ref<Image>(p_image), 0); ResourceSaver::save(src_img, t); Error err = OS::get_singleton()->execute(ttpath, args, true); - ERR_EXPLAIN(TTR("Could not execute PVRTC tool:") + " " + ttpath); - ERR_FAIL_COND(err != OK); + if (err != OK) { + // Clean up generated files. + DirAccess::remove_file_or_error(src_img); + DirAccess::remove_file_or_error(dst_img); + ERR_FAIL_MSG("Could not execute PVRTC tool: " + ttpath); + } t = ResourceLoader::load(dst_img, "Texture"); - - ERR_EXPLAIN(TTR("Can't load back converted image using PVRTC tool:") + " " + dst_img); - ERR_FAIL_COND(t.is_null()); + if (t.is_null()) { + // Clean up generated files. + DirAccess::remove_file_or_error(src_img); + DirAccess::remove_file_or_error(dst_img); + ERR_FAIL_MSG("Can't load back converted image using PVRTC tool."); + } p_image->copy_internals_from(t->get_data()); + + // Clean up generated files. + DirAccess::remove_file_or_error(src_img); + DirAccess::remove_file_or_error(dst_img); } static void _compress_pvrtc2(Image *p_image) { diff --git a/editor/quick_open.cpp b/editor/quick_open.cpp index dc2f098333..4e1c900ee4 100644 --- a/editor/quick_open.cpp +++ b/editor/quick_open.cpp @@ -256,16 +256,16 @@ void EditorQuickOpen::_confirmed() { void EditorQuickOpen::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - connect("confirmed", this, "_confirmed"); - search_box->set_right_icon(get_icon("Search", "EditorIcons")); search_box->set_clear_button_enabled(true); + FALLTHROUGH; + } + case NOTIFICATION_THEME_CHANGED: { + search_box->set_right_icon(get_icon("Search", "EditorIcons")); } break; case NOTIFICATION_EXIT_TREE: { - disconnect("confirmed", this, "_confirmed"); } break; } @@ -289,7 +289,6 @@ EditorQuickOpen::EditorQuickOpen() { VBoxContainer *vbc = memnew(VBoxContainer); add_child(vbc); - //set_child_rect(vbc); search_box = memnew(LineEdit); vbc->add_margin_child(TTR("Search:"), search_box); search_box->connect("text_changed", this, "_text_changed"); @@ -302,6 +301,7 @@ EditorQuickOpen::EditorQuickOpen() { set_hide_on_ok(false); search_options->connect("item_activated", this, "_confirmed"); search_options->set_hide_root(true); + search_options->set_hide_folding(true); search_options->add_constant_override("draw_guides", 1); ei = "EditorIcons"; ot = "Object"; diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index aeee829de2..032b3a19a6 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -399,6 +399,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } Node *selected = scene_tree->get_selected(); + if (!selected && !editor_selection->get_selected_node_list().empty()) + selected = editor_selection->get_selected_node_list().front()->get(); + if (selected) create_dialog->popup_create(false, true, selected->get_class()); @@ -1983,6 +1986,10 @@ void SceneTreeDock::_create() { } else if (current_option == TOOL_REPLACE) { List<Node *> selection = editor_selection->get_selected_node_list(); ERR_FAIL_COND(selection.size() <= 0); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action(TTR("Change type of node(s)")); + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Node *n = E->get(); ERR_FAIL_COND(!n); @@ -1993,8 +2000,13 @@ void SceneTreeDock::_create() { Node *newnode = Object::cast_to<Node>(c); ERR_FAIL_COND(!newnode); - replace_node(n, newnode); + ur->add_do_method(this, "replace_node", n, newnode, true, false); + ur->add_do_reference(newnode); + ur->add_undo_method(this, "replace_node", newnode, n, false, false); + ur->add_undo_reference(n); } + + ur->commit_action(); } else if (current_option == TOOL_REPARENT_TO_NEW_NODE) { List<Node *> selection = editor_selection->get_selected_node_list(); ERR_FAIL_COND(selection.size() <= 0); diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index ed9a24311d..7d0f40fe91 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -44,6 +44,23 @@ void ScriptCreateDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: case NOTIFICATION_ENTER_TREE: { + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + String lang = ScriptServer::get_language(i)->get_name(); + Ref<Texture> lang_icon = get_icon(lang, "EditorIcons"); + if (lang_icon.is_valid()) { + language_menu->set_item_icon(i, lang_icon); + } + } + String last_lang = EditorSettings::get_singleton()->get_project_metadata("script_setup", "last_selected_language", ""); + Ref<Texture> last_lang_icon; + if (!last_lang.empty()) { + last_lang_icon = get_icon(last_lang, "EditorIcons"); + } else { + last_lang_icon = language_menu->get_item_icon(default_language); + } + if (last_lang_icon.is_valid()) { + language_menu->set_icon(last_lang_icon); + } path_button->set_icon(get_icon("Folder", "EditorIcons")); parent_browse_button->set_icon(get_icon("Folder", "EditorIcons")); parent_search_button->set_icon(get_icon("ClassList", "EditorIcons")); @@ -671,13 +688,13 @@ ScriptCreateDialog::ScriptCreateDialog() { gc->add_child(l); gc->add_child(language_menu); - int default_lang = 0; + default_language = 0; for (int i = 0; i < ScriptServer::get_language_count(); i++) { String lang = ScriptServer::get_language(i)->get_name(); language_menu->add_item(lang); if (lang == "GDScript") { - default_lang = i; + default_language = i; } } @@ -691,8 +708,8 @@ ScriptCreateDialog::ScriptCreateDialog() { } } } else { - language_menu->select(default_lang); - current_language = default_lang; + language_menu->select(default_language); + current_language = default_language; } language_menu->connect("item_selected", this, "_lang_changed"); diff --git a/editor/script_create_dialog.h b/editor/script_create_dialog.h index 288b8f604b..202846fd3c 100644 --- a/editor/script_create_dialog.h +++ b/editor/script_create_dialog.h @@ -76,6 +76,7 @@ class ScriptCreateDialog : public ConfirmationDialog { bool is_built_in; bool built_in_enabled; int current_language; + int default_language; bool re_check_path; String script_template; Vector<String> template_list; diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index cbfd0f3742..f7ba5e5e3c 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -36,6 +36,7 @@ #include "scene/3d/baked_lightmap.h" #include "scene/3d/collision_polygon.h" #include "scene/3d/collision_shape.h" +#include "scene/3d/cpu_particles.h" #include "scene/3d/gi_probe.h" #include "scene/3d/light.h" #include "scene/3d/listener.h" @@ -2415,6 +2416,33 @@ void VisibilityNotifierGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { //// +CPUParticlesGizmoPlugin::CPUParticlesGizmoPlugin() { + create_icon_material("particles_icon", SpatialEditor::get_singleton()->get_icon("GizmoCPUParticles", "EditorIcons")); +} + +bool CPUParticlesGizmoPlugin::has_gizmo(Spatial *p_spatial) { + return Object::cast_to<CPUParticles>(p_spatial) != NULL; +} + +String CPUParticlesGizmoPlugin::get_name() const { + return "CPUParticles"; +} + +int CPUParticlesGizmoPlugin::get_priority() const { + return -1; +} + +bool CPUParticlesGizmoPlugin::is_selectable_when_hidden() const { + return true; +} + +void CPUParticlesGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { + Ref<Material> icon = get_material("particles_icon", p_gizmo); + p_gizmo->add_unscaled_billboard(icon, 0.05); +} + +//// + ParticlesGizmoPlugin::ParticlesGizmoPlugin() { Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/particles", Color(0.8, 0.7, 0.4)); create_material("particles_material", gizmo_color); diff --git a/editor/spatial_editor_gizmos.h b/editor/spatial_editor_gizmos.h index 3661df4bad..317ea0c570 100644 --- a/editor/spatial_editor_gizmos.h +++ b/editor/spatial_editor_gizmos.h @@ -249,6 +249,18 @@ public: VisibilityNotifierGizmoPlugin(); }; +class CPUParticlesGizmoPlugin : public EditorSpatialGizmoPlugin { + GDCLASS(CPUParticlesGizmoPlugin, EditorSpatialGizmoPlugin); + +public: + bool has_gizmo(Spatial *p_spatial); + String get_name() const; + int get_priority() const; + bool is_selectable_when_hidden() const; + void redraw(EditorSpatialGizmo *p_gizmo); + CPUParticlesGizmoPlugin(); +}; + class ParticlesGizmoPlugin : public EditorSpatialGizmoPlugin { GDCLASS(ParticlesGizmoPlugin, EditorSpatialGizmoPlugin); diff --git a/main/main.cpp b/main/main.cpp index 39cd2548fb..027273c4f4 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -816,10 +816,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph String bp = breakpoints[i]; int sp = bp.find_last(":"); - if (sp == -1) { - ERR_EXPLAIN("Invalid breakpoint: '" + bp + "', expected file:line format."); - ERR_CONTINUE(true); - } + ERR_CONTINUE_MSG(sp == -1, "Invalid breakpoint: '" + bp + "', expected file:line format."); script_debugger->insert_breakpoint(bp.substr(sp + 1, bp.length()).to_int(), bp.substr(0, sp)); } @@ -1375,10 +1372,7 @@ bool Main::start() { { DirAccessRef da = DirAccess::open(doc_tool); - if (!da) { - ERR_EXPLAIN("Argument supplied to --doctool must be a base Godot build directory"); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(!da, false, "Argument supplied to --doctool must be a base Godot build directory."); } DocData doc; doc.generate(doc_base); @@ -1462,8 +1456,7 @@ bool Main::start() { } else if (script != "") { Ref<Script> script_res = ResourceLoader::load(script); - ERR_EXPLAIN("Can't load script: " + script); - ERR_FAIL_COND_V(script_res.is_null(), false); + ERR_FAIL_COND_V_MSG(script_res.is_null(), false, "Can't load script: " + script); if (check_only) { return false; @@ -1477,8 +1470,7 @@ bool Main::start() { if (!script_loop) { if (obj) memdelete(obj); - ERR_EXPLAIN("Can't load script '" + script + "', it does not inherit from a MainLoop type"); - ERR_FAIL_V(false); + ERR_FAIL_V_MSG(false, "Can't load script '" + script + "', it does not inherit from a MainLoop type."); } script_loop->set_init_script(script_res); @@ -1502,17 +1494,13 @@ bool Main::start() { } else { Object *ml = ClassDB::instance(main_loop_type); - if (!ml) { - ERR_EXPLAIN("Can't instance MainLoop type"); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(!ml, false, "Can't instance MainLoop type."); main_loop = Object::cast_to<MainLoop>(ml); if (!main_loop) { memdelete(ml); - ERR_EXPLAIN("Invalid MainLoop type"); - ERR_FAIL_V(false); + ERR_FAIL_V_MSG(false, "Invalid MainLoop type."); } } } @@ -1575,8 +1563,7 @@ bool Main::start() { } RES res = ResourceLoader::load(path); - ERR_EXPLAIN("Can't autoload: " + path); - ERR_CONTINUE(res.is_null()); + ERR_CONTINUE_MSG(res.is_null(), "Can't autoload: " + path); Node *n = NULL; if (res->is_class("PackedScene")) { Ref<PackedScene> ps = res; @@ -1585,20 +1572,17 @@ bool Main::start() { Ref<Script> script_res = res; StringName ibt = script_res->get_instance_base_type(); bool valid_type = ClassDB::is_parent_class(ibt, "Node"); - ERR_EXPLAIN("Script does not inherit a Node: " + path); - ERR_CONTINUE(!valid_type); + ERR_CONTINUE_MSG(!valid_type, "Script does not inherit a Node: " + path); Object *obj = ClassDB::instance(ibt); - ERR_EXPLAIN("Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt)); - ERR_CONTINUE(obj == NULL); + ERR_CONTINUE_MSG(obj == NULL, "Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt)); n = Object::cast_to<Node>(obj); n->set_script(script_res.get_ref_ptr()); } - ERR_EXPLAIN("Path in autoload not a node or script: " + path); - ERR_CONTINUE(!n); + ERR_CONTINUE_MSG(!n, "Path in autoload not a node or script: " + path); n->set_name(name); //defer so references are all valid on _ready() @@ -1756,7 +1740,7 @@ bool Main::start() { if (!project_manager && !editor) { // game - // Load SSL Certificates from Project Settings (or builtin) + // Load SSL Certificates from Project Settings (or builtin). StreamPeerSSL::load_certs_from_memory(StreamPeerSSL::get_project_cert_array()); if (game_path != "") { @@ -1765,8 +1749,7 @@ bool Main::start() { if (scenedata.is_valid()) scene = scenedata->instance(); - ERR_EXPLAIN("Failed loading scene: " + local_game_path); - ERR_FAIL_COND_V(!scene, false); + ERR_FAIL_COND_V_MSG(!scene, false, "Failed loading scene: " + local_game_path); sml->add_current_scene(scene); #ifdef OSX_ENABLED @@ -1810,14 +1793,14 @@ bool Main::start() { } if (project_manager || editor) { - // Load SSL Certificates from Editor Settings (or builtin) + // Load SSL Certificates from Editor Settings (or builtin). String certs = EditorSettings::get_singleton()->get_setting("network/ssl/editor_ssl_certificates").operator String(); if (certs != "") StreamPeerSSL::load_certs_from_file(certs); else StreamPeerSSL::load_certs_from_memory(StreamPeerSSL::get_project_cert_array()); - // Hide console window if requested (Windows-only) + // Hide console window if requested (Windows-only). bool hide_console = EditorSettings::get_singleton()->get_setting("interface/editor/hide_console_window"); OS::get_singleton()->set_console_visible(!hide_console); } @@ -1854,7 +1837,7 @@ bool Main::is_iterating() { return iterating > 0; } -// For performance metrics +// For performance metrics. static uint64_t physics_process_max = 0; static uint64_t idle_process_max = 0; diff --git a/main/tests/test_gdscript.cpp b/main/tests/test_gdscript.cpp index e82af93293..b2b2c22bf9 100644 --- a/main/tests/test_gdscript.cpp +++ b/main/tests/test_gdscript.cpp @@ -300,14 +300,11 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) { } break; default: { - String error = "Parser bug at " + itos(p_expr->line) + ", invalid expression type: " + itos(p_expr->type); - ERR_EXPLAIN(error); - ERR_FAIL_V(""); + ERR_FAIL_V_MSG("", "Parser bug at " + itos(p_expr->line) + ", invalid expression type: " + itos(p_expr->type)); } } return txt; - //return "("+txt+")"; } static void _parser_show_block(const GDScriptParser::BlockNode *p_block, int p_indent) { @@ -910,8 +907,7 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String if (incr == 0) { - ERR_EXPLAIN("unhandled opcode: " + itos(code[ip])); - ERR_BREAK(true); + ERR_BREAK_MSG(true, "Unhandled opcode: " + itos(code[ip])); } ip += incr; @@ -936,11 +932,7 @@ MainLoop *test(TestType p_type) { } FileAccess *fa = FileAccess::open(test, FileAccess::READ); - - if (!fa) { - ERR_EXPLAIN("Could not open file: " + test); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!fa, NULL, "Could not open file: " + test); Vector<uint8_t> buf; int flen = fa->get_len(); diff --git a/main/tests/test_math.cpp b/main/tests/test_math.cpp index f341159079..68ecb2b1b2 100644 --- a/main/tests/test_math.cpp +++ b/main/tests/test_math.cpp @@ -494,11 +494,7 @@ MainLoop *test() { } FileAccess *fa = FileAccess::open(test, FileAccess::READ); - - if (!fa) { - ERR_EXPLAIN("Could not open file: " + test); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!fa, NULL, "Could not open file: " + test); Vector<uint8_t> buf; int flen = fa->get_len(); diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp index ab5fb64252..7a41880645 100644 --- a/main/tests/test_string.cpp +++ b/main/tests/test_string.cpp @@ -432,6 +432,10 @@ bool test_26() { OS::get_singleton()->print("\n\nTest 26: RegEx substitution\n"); +#ifndef MODULE_REGEX_ENABLED + OS::get_singleton()->print("\tRegEx module disabled, can't run test."); + return false; +#else String s = "Double all the vowels."; OS::get_singleton()->print("\tString: %ls\n", s.c_str()); @@ -443,6 +447,7 @@ bool test_26() { OS::get_singleton()->print("\tResult: %ls\n", s.c_str()); return (s == "Doouublee aall thee vooweels."); +#endif } struct test_27_data { diff --git a/modules/assimp/editor_scene_importer_assimp.cpp b/modules/assimp/editor_scene_importer_assimp.cpp index 65fa8b6459..05f9120a07 100644 --- a/modules/assimp/editor_scene_importer_assimp.cpp +++ b/modules/assimp/editor_scene_importer_assimp.cpp @@ -150,8 +150,7 @@ Node *EditorSceneImporterAssimp::import_scene(const String &p_path, uint32_t p_f 0; const aiScene *scene = importer.ReadFile(s_path.c_str(), post_process_Steps); - ERR_EXPLAIN(String("Open Asset Import failed to open: ") + String(importer.GetErrorString())); - ERR_FAIL_COND_V(scene == NULL, NULL); + ERR_FAIL_COND_V_MSG(scene == NULL, NULL, String("Open Asset Import failed to open: ") + String(importer.GetErrorString()) + "."); return _generate_scene(p_path, scene, p_flags, p_bake_fps, max_bone_weights); } @@ -348,8 +347,7 @@ void EditorSceneImporterAssimp::_fill_node_relationships(ImportState &state, con } else if (ownership[name] != p_skeleton_id) { //oh, it's from another skeleton? fine.. reparent all bones to this skeleton. int prev_owner = ownership[name]; - ERR_EXPLAIN("A previous skeleton exists for bone '" + name + "', this type of skeleton layout is unsupported."); - ERR_FAIL_COND(skeleton_map.has(prev_owner)); + ERR_FAIL_COND_MSG(skeleton_map.has(prev_owner), "A previous skeleton exists for bone '" + name + "', this type of skeleton layout is unsupported."); for (Map<String, int>::Element *E = ownership.front(); E; E = E->next()) { if (E->get() == prev_owner) { E->get() = p_skeleton_id; @@ -779,8 +777,7 @@ Ref<Texture> EditorSceneImporterAssimp::_load_texture(ImportState &state, String t->set_storage(ImageTexture::STORAGE_COMPRESS_LOSSY); return t; } else if (tex->CheckFormat("dds")) { - ERR_EXPLAIN("Open Asset Import: Embedded dds not implemented"); - ERR_FAIL_COND_V(true, Ref<Texture>()); + ERR_FAIL_V_MSG(Ref<Texture>(), "Open Asset Import: Embedded dds not implemented."); //Ref<Image> img = Image::_dds_mem_loader_func((uint8_t *)tex->pcData, tex->mWidth); //ERR_FAIL_COND_V(img.is_null(), Ref<Texture>()); //Ref<ImageTexture> t; diff --git a/modules/bmp/image_loader_bmp.cpp b/modules/bmp/image_loader_bmp.cpp index 88732dff33..5a32fa1c2c 100644 --- a/modules/bmp/image_loader_bmp.cpp +++ b/modules/bmp/image_loader_bmp.cpp @@ -241,9 +241,9 @@ Error ImageLoaderBMP::load_image(Ref<Image> p_image, FileAccess *f, case BI_CMYKRLE8: case BI_CMYKRLE4: { // Stop parsing - ERR_EXPLAIN("Compressed BMP files are not supported: " + f->get_path()); + String bmp_path = f->get_path(); f->close(); - ERR_FAIL_V(ERR_UNAVAILABLE); + ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Compressed BMP files are not supported: " + bmp_path + "."); } break; } // Don't rely on sizeof(bmp_file_header) as structure padding diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp index 038001996d..e01928191a 100644 --- a/modules/bullet/bullet_physics_server.cpp +++ b/modules/bullet/bullet_physics_server.cpp @@ -1548,8 +1548,7 @@ void BulletPhysicsServer::free(RID p_rid) { bulletdelete(space); } else { - ERR_EXPLAIN("Invalid ID"); - ERR_FAIL(); + ERR_FAIL_MSG("Invalid ID."); } } diff --git a/modules/bullet/cone_twist_joint_bullet.cpp b/modules/bullet/cone_twist_joint_bullet.cpp index bc7fd52cf6..97b9a81f77 100644 --- a/modules/bullet/cone_twist_joint_bullet.cpp +++ b/modules/bullet/cone_twist_joint_bullet.cpp @@ -83,8 +83,7 @@ void ConeTwistJointBullet::set_param(PhysicsServer::ConeTwistJointParam p_param, coneConstraint->setLimit(coneConstraint->getSwingSpan1(), coneConstraint->getSwingSpan2(), coneConstraint->getTwistSpan(), coneConstraint->getLimitSoftness(), coneConstraint->getBiasFactor(), p_value); break; default: - ERR_EXPLAIN("This parameter " + itos(p_param) + " is deprecated"); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The parameter " + itos(p_param) + " is deprecated."); break; } } @@ -102,8 +101,7 @@ real_t ConeTwistJointBullet::get_param(PhysicsServer::ConeTwistJointParam p_para case PhysicsServer::CONE_TWIST_JOINT_RELAXATION: return coneConstraint->getRelaxationFactor(); default: - ERR_EXPLAIN("This parameter " + itos(p_param) + " is deprecated"); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The parameter " + itos(p_param) + " is deprecated."); return 0; } } diff --git a/modules/bullet/generic_6dof_joint_bullet.cpp b/modules/bullet/generic_6dof_joint_bullet.cpp index 0d2c46c579..4aae87c220 100644 --- a/modules/bullet/generic_6dof_joint_bullet.cpp +++ b/modules/bullet/generic_6dof_joint_bullet.cpp @@ -174,8 +174,7 @@ void Generic6DOFJointBullet::set_param(Vector3::Axis p_axis, PhysicsServer::G6DO sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_equilibriumPoint = p_value; break; default: - ERR_EXPLAIN("This parameter " + itos(p_param) + " is deprecated"); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The parameter " + itos(p_param) + " is deprecated."); break; } } @@ -216,8 +215,7 @@ real_t Generic6DOFJointBullet::get_param(Vector3::Axis p_axis, PhysicsServer::G6 case PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT: return sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_equilibriumPoint; default: - ERR_EXPLAIN("This parameter " + itos(p_param) + " is deprecated"); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The parameter " + itos(p_param) + " is deprecated."); return 0; } } @@ -255,8 +253,7 @@ void Generic6DOFJointBullet::set_flag(Vector3::Axis p_axis, PhysicsServer::G6DOF sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_enableSpring = p_value; break; default: - ERR_EXPLAIN("This flag " + itos(p_flag) + " is deprecated"); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The flag " + itos(p_flag) + " is deprecated."); break; } } diff --git a/modules/bullet/hinge_joint_bullet.cpp b/modules/bullet/hinge_joint_bullet.cpp index b7e1e1a4c2..4d26e729db 100644 --- a/modules/bullet/hinge_joint_bullet.cpp +++ b/modules/bullet/hinge_joint_bullet.cpp @@ -117,8 +117,7 @@ void HingeJointBullet::set_param(PhysicsServer::HingeJointParam p_param, real_t hingeConstraint->setMaxMotorImpulse(p_value); break; default: - ERR_EXPLAIN("The HingeJoint parameter " + itos(p_param) + " is deprecated."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The HingeJoint parameter " + itos(p_param) + " is deprecated."); break; } } @@ -143,8 +142,7 @@ real_t HingeJointBullet::get_param(PhysicsServer::HingeJointParam p_param) const case PhysicsServer::HINGE_JOINT_MOTOR_MAX_IMPULSE: return hingeConstraint->getMaxMotorImpulse(); default: - ERR_EXPLAIN("The HingeJoint parameter " + itos(p_param) + " is deprecated."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The HingeJoint parameter " + itos(p_param) + " is deprecated."); return 0; } } diff --git a/modules/bullet/pin_joint_bullet.cpp b/modules/bullet/pin_joint_bullet.cpp index c9c4d1af7e..8d404e7f04 100644 --- a/modules/bullet/pin_joint_bullet.cpp +++ b/modules/bullet/pin_joint_bullet.cpp @@ -85,8 +85,7 @@ real_t PinJointBullet::get_param(PhysicsServer::PinJointParam p_param) const { case PhysicsServer::PIN_JOINT_IMPULSE_CLAMP: return p2pConstraint->m_setting.m_impulseClamp; default: - ERR_EXPLAIN("This parameter " + itos(p_param) + " is deprecated"); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The parameter " + itos(p_param) + " is deprecated."); return 0; } } diff --git a/modules/bullet/shape_bullet.cpp b/modules/bullet/shape_bullet.cpp index f15bcec914..85f47c3bbb 100644 --- a/modules/bullet/shape_bullet.cpp +++ b/modules/bullet/shape_bullet.cpp @@ -505,8 +505,7 @@ void HeightMapShapeBullet::set_data(const Variant &p_data) { } } else { - ERR_EXPLAIN("Expected PoolRealArray or float Image."); - ERR_FAIL(); + ERR_FAIL_MSG("Expected PoolRealArray or float Image."); } ERR_FAIL_COND(l_width <= 0); diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index f475ba23f6..d2b16b0fd1 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -581,10 +581,8 @@ void SpaceBullet::create_empty_world(bool p_create_soft_world) { } else { world_mem = malloc(sizeof(btDiscreteDynamicsWorld)); } - if (!world_mem) { - ERR_EXPLAIN("Out of memory"); - ERR_FAIL(); - } + + ERR_FAIL_COND_MSG(!world_mem, "Out of memory."); if (p_create_soft_world) { collisionConfiguration = bulletnew(GodotSoftCollisionConfiguration(static_cast<btDiscreteDynamicsWorld *>(world_mem))); diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index 4628bd9a5b..0220dcae4a 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -108,8 +108,7 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, if (r_error) *r_error = ERR_FILE_CORRUPT; - ERR_EXPLAIN("Unable to open DDS texture file: " + p_path); - ERR_FAIL_COND_V(err != OK, RES()); + ERR_FAIL_COND_V_MSG(err != OK, RES(), "Unable to open DDS texture file: " + p_path + "."); uint32_t magic = f->get_32(); uint32_t hsize = f->get_32(); @@ -128,8 +127,7 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, if (magic != DDS_MAGIC || hsize != 124 || !(flags & DDSD_PIXELFORMAT) || !(flags & DDSD_CAPS)) { - ERR_EXPLAIN("Invalid or Unsupported DDS texture file: " + p_path); - ERR_FAIL_V(RES()); + ERR_FAIL_V_MSG(RES(), "Invalid or unsupported DDS texture file: " + p_path + "."); } /* uint32_t format_size = */ f->get_32(); @@ -218,9 +216,7 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, } else { printf("unrecognized fourcc %x format_flags: %x - rgbbits %i - red_mask %x green mask %x blue mask %x alpha mask %x\n", format_fourcc, format_flags, format_rgb_bits, format_red_mask, format_green_mask, format_blue_mask, format_alpha_mask); - ERR_EXPLAIN("Unrecognized or Unsupported color layout in DDS: " + p_path); - - ERR_FAIL_V(RES()); + ERR_FAIL_V_MSG(RES(), "Unrecognized or unsupported color layout in DDS: " + p_path + "."); } if (!(flags & DDSD_MIPMAPCOUNT)) diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index a5a356ced2..44f69ca261 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -543,10 +543,7 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer if (target_peer != 0) { E = peer_map.find(ABS(target_peer)); - if (!E) { - ERR_EXPLAIN("Invalid Target Peer: " + itos(target_peer)); - ERR_FAIL_V(ERR_INVALID_PARAMETER); - } + ERR_FAIL_COND_V_MSG(!E, ERR_INVALID_PARAMETER, "Invalid target peer: " + itos(target_peer) + "."); } ENetPacket *packet = enet_packet_create(NULL, p_buffer_size + 8, packet_flags); @@ -794,11 +791,7 @@ int NetworkedMultiplayerENet::get_peer_port(int p_peer_id) const { void NetworkedMultiplayerENet::set_transfer_channel(int p_channel) { ERR_FAIL_COND(p_channel < -1 || p_channel >= channel_count); - - if (p_channel == SYSCH_CONFIG) { - ERR_EXPLAIN("Channel " + itos(SYSCH_CONFIG) + " is reserved"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(p_channel == SYSCH_CONFIG, "Channel " + itos(SYSCH_CONFIG) + " is reserved."); transfer_channel = p_channel; } diff --git a/modules/etc/texture_loader_pkm.cpp b/modules/etc/texture_loader_pkm.cpp index ff925480b8..3337460dfc 100644 --- a/modules/etc/texture_loader_pkm.cpp +++ b/modules/etc/texture_loader_pkm.cpp @@ -56,8 +56,7 @@ RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, if (r_error) *r_error = ERR_FILE_CORRUPT; - ERR_EXPLAIN("Unable to open PKM texture file: " + p_path); - ERR_FAIL_COND_V(err != OK, RES()); + ERR_FAIL_COND_V_MSG(err != OK, RES(), "Unable to open PKM texture file: " + p_path + "."); // big endian f->set_endian_swap(true); diff --git a/modules/gdnative/arvr/arvr_interface_gdnative.cpp b/modules/gdnative/arvr/arvr_interface_gdnative.cpp index 64e2c362b2..bd6eb575d0 100644 --- a/modules/gdnative/arvr/arvr_interface_gdnative.cpp +++ b/modules/gdnative/arvr/arvr_interface_gdnative.cpp @@ -245,8 +245,7 @@ extern "C" { void GDAPI godot_arvr_register_interface(const godot_arvr_interface_gdnative *p_interface) { // If our major version is 0 or bigger then 10, we're likely looking at our constructor pointer from an older plugin - ERR_EXPLAINC("GDNative ARVR interfaces build for Godot 3.0 are not supported"); - ERR_FAIL_COND((p_interface->version.major == 0) || (p_interface->version.major > 10)); + ERR_FAIL_COND_MSG((p_interface->version.major == 0) || (p_interface->version.major > 10), "GDNative ARVR interfaces build for Godot 3.0 are not supported."); Ref<ARVRInterfaceGDNative> new_interface; new_interface.instance(); diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 4eb9a2a0a3..783ad4e147 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -268,8 +268,7 @@ void GDNative::_bind_methods() { } void GDNative::set_library(Ref<GDNativeLibrary> p_library) { - ERR_EXPLAIN("Tried to change library of GDNative when it is already set"); - ERR_FAIL_COND(library.is_valid()); + ERR_FAIL_COND_MSG(library.is_valid(), "Tried to change library of GDNative when it is already set."); library = p_library; } diff --git a/modules/gdnative/gdnative_builders.py b/modules/gdnative/gdnative_builders.py index 7ab0e01108..20c1a2233c 100644 --- a/modules/gdnative/gdnative_builders.py +++ b/modules/gdnative/gdnative_builders.py @@ -185,7 +185,7 @@ def _build_gdnative_api_struct_source(api): 'extern const godot_gdnative_core_' + ('{0}_{1}_api_struct api_{0}_{1}'.format(core['version']['major'], core['version']['minor'])) + ' = {', '\tGDNATIVE_' + core['type'] + ',', '\t{' + str(core['version']['major']) + ', ' + str(core['version']['minor']) + '},', - '\t' + ('NULL' if not core['next'] else ('(const godot_gdnative_api_struct *)& api_{0}_{1}'.format(core['version']['major'], core['version']['minor']))) + ',' + '\t' + ('NULL' if not core['next'] else ('(const godot_gdnative_api_struct *)& api_{0}_{1}'.format(core['next']['version']['major'], core['next']['version']['minor']))) + ',' ] for funcdef in core['api']: diff --git a/modules/gdnative/nativescript/godot_nativescript.cpp b/modules/gdnative/nativescript/godot_nativescript.cpp index 863999d6d4..979e47f7b9 100644 --- a/modules/gdnative/nativescript/godot_nativescript.cpp +++ b/modules/gdnative/nativescript/godot_nativescript.cpp @@ -104,11 +104,7 @@ void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const cha String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to register method on non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to register method on non-existent class."); NativeScriptDesc::Method method; method.method = p_method; @@ -123,11 +119,7 @@ void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const c String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to register method on non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to register method on non-existent class."); NativeScriptDesc::Property property; property.default_value = *(Variant *)&p_attr->default_value; @@ -148,11 +140,7 @@ void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const cha String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to register method on non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to register method on non-existent class."); List<PropertyInfo> args; Vector<Variant> default_args; @@ -213,17 +201,10 @@ void GDAPI godot_nativescript_set_method_argument_information(void *p_gdnative_h String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to add argument information for a method on a non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to add argument information for a method on a non-existent class."); Map<StringName, NativeScriptDesc::Method>::Element *method = E->get().methods.find(p_function_name); - if (!method) { - ERR_EXPLAIN("Attempted to add argument information to non-existent method!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!method, "Attempted to add argument information to non-existent method."); MethodInfo *method_information = &method->get().info; @@ -247,11 +228,7 @@ void GDAPI godot_nativescript_set_class_documentation(void *p_gdnative_handle, c String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to add documentation to a non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a non-existent class."); E->get().documentation = *(String *)&p_documentation; } @@ -260,17 +237,10 @@ void GDAPI godot_nativescript_set_method_documentation(void *p_gdnative_handle, String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to add documentation to a method on a non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a method on a non-existent class."); Map<StringName, NativeScriptDesc::Method>::Element *method = E->get().methods.find(p_function_name); - if (!method) { - ERR_EXPLAIN("Attempted to add documentatino to non-existent method!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!method, "Attempted to add documentation to non-existent method."); method->get().documentation = *(String *)&p_documentation; } @@ -279,17 +249,10 @@ void GDAPI godot_nativescript_set_property_documentation(void *p_gdnative_handle String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to add documentation to a property on a non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a property on a non-existent class."); OrderedHashMap<StringName, NativeScriptDesc::Property>::Element property = E->get().properties.find(p_path); - if (!property) { - ERR_EXPLAIN("Attempted to add documentation to non-existent property!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!property, "Attempted to add documentation to non-existent property."); property.get().documentation = *(String *)&p_documentation; } @@ -298,17 +261,10 @@ void GDAPI godot_nativescript_set_signal_documentation(void *p_gdnative_handle, String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to add documentation to a signal on a non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to add documentation to a signal on a non-existent class."); Map<StringName, NativeScriptDesc::Signal>::Element *signal = E->get().signals_.find(p_signal_name); - if (!signal) { - ERR_EXPLAIN("Attempted to add documentation to non-existent signal!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!signal, "Attempted to add documentation to non-existent signal."); signal->get().documentation = *(String *)&p_documentation; } @@ -325,11 +281,7 @@ void GDAPI godot_nativescript_set_type_tag(void *p_gdnative_handle, const char * String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); - - if (!E) { - ERR_EXPLAIN("Attempted to set type tag on a non-existent class!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!E, "Attempted to set type tag on a non-existent class."); E->get().type_tag = p_type_tag; } diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index f30c9da4c1..9f7c3880ec 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -402,10 +402,7 @@ void NativeScript::get_script_property_list(List<PropertyInfo> *p_list) const { String NativeScript::get_class_documentation() const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) { - ERR_EXPLAIN("Attempt to get class documentation on invalid NativeScript"); - ERR_FAIL_V(""); - } + ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get class documentation on invalid NativeScript."); return script_data->documentation; } @@ -413,10 +410,7 @@ String NativeScript::get_class_documentation() const { String NativeScript::get_method_documentation(const StringName &p_method) const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) { - ERR_EXPLAIN("Attempt to get method documentation on invalid NativeScript"); - ERR_FAIL_V(""); - } + ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get method documentation on invalid NativeScript."); while (script_data) { @@ -429,17 +423,13 @@ String NativeScript::get_method_documentation(const StringName &p_method) const script_data = script_data->base_data; } - ERR_EXPLAIN("Attempt to get method documentation for non-existent method"); - ERR_FAIL_V(""); + ERR_FAIL_V_MSG("", "Attempt to get method documentation for non-existent method."); } String NativeScript::get_signal_documentation(const StringName &p_signal_name) const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) { - ERR_EXPLAIN("Attempt to get signal documentation on invalid NativeScript"); - ERR_FAIL_V(""); - } + ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get signal documentation on invalid NativeScript."); while (script_data) { @@ -452,17 +442,13 @@ String NativeScript::get_signal_documentation(const StringName &p_signal_name) c script_data = script_data->base_data; } - ERR_EXPLAIN("Attempt to get signal documentation for non-existent signal"); - ERR_FAIL_V(""); + ERR_FAIL_V_MSG("", "Attempt to get signal documentation for non-existent signal."); } String NativeScript::get_property_documentation(const StringName &p_path) const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) { - ERR_EXPLAIN("Attempt to get property documentation on invalid NativeScript"); - ERR_FAIL_V(""); - } + ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get property documentation on invalid NativeScript."); while (script_data) { @@ -475,8 +461,7 @@ String NativeScript::get_property_documentation(const StringName &p_path) const script_data = script_data->base_data; } - ERR_EXPLAIN("Attempt to get property documentation for non-existent signal"); - ERR_FAIL_V(""); + ERR_FAIL_V_MSG("", "Attempt to get property documentation for non-existent signal."); } Variant NativeScript::_new(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { @@ -655,10 +640,7 @@ void NativeScriptInstance::get_property_list(List<PropertyInfo> *p_properties) c Variant res = *(Variant *)&result; godot_variant_destroy(&result); - if (res.get_type() != Variant::ARRAY) { - ERR_EXPLAIN("_get_property_list must return an array of dictionaries"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(res.get_type() != Variant::ARRAY, "_get_property_list must return an array of dictionaries."); Array arr = res; for (int i = 0; i < arr.size(); i++) { @@ -780,8 +762,7 @@ String NativeScriptInstance::to_string(bool *r_valid) { if (ret.get_type() != Variant::STRING) { if (r_valid) *r_valid = false; - ERR_EXPLAIN("Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); - ERR_FAIL_V(String()); + ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); } if (r_valid) *r_valid = true; @@ -1344,10 +1325,7 @@ void NativeScriptLanguage::unregister_binding_functions(int p_idx) { void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_object) { ERR_FAIL_INDEX_V(p_idx, binding_functions.size(), NULL); - if (!binding_functions[p_idx].first) { - ERR_EXPLAIN("Tried to get binding data for a nativescript binding that does not exist"); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!binding_functions[p_idx].first, NULL, "Tried to get binding data for a nativescript binding that does not exist."); Vector<void *> *binding_data = (Vector<void *> *)p_object->get_script_instance_binding(lang_idx); @@ -1499,8 +1477,7 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { #endif // See if this library was "registered" already. const String &lib_path = lib->get_current_library_path(); - ERR_EXPLAIN(lib->get_name() + " does not have a library for the current platform"); - ERR_FAIL_COND(lib_path.length() == 0); + ERR_FAIL_COND_MSG(lib_path.length() == 0, lib->get_name() + " does not have a library for the current platform."); Map<String, Ref<GDNative> >::Element *E = library_gdnatives.find(lib_path); if (!E) { diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp index 3ecb29404a..b82823ab64 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.cpp +++ b/modules/gdnative/pluginscript/pluginscript_script.cpp @@ -35,16 +35,14 @@ #include "pluginscript_script.h" #ifdef DEBUG_ENABLED -#define __ASSERT_SCRIPT_REASON "Cannot retrieve pluginscript class for this script, is you code correct ?" -#define ASSERT_SCRIPT_VALID() \ - { \ - ERR_EXPLAIN(__ASSERT_SCRIPT_REASON); \ - ERR_FAIL_COND(!can_instance()); \ +#define __ASSERT_SCRIPT_REASON "Cannot retrieve PluginScript class for this script, is your code correct?" +#define ASSERT_SCRIPT_VALID() \ + { \ + ERR_FAIL_COND_MSG(!can_instance(), __ASSERT_SCRIPT_REASON); \ } -#define ASSERT_SCRIPT_VALID_V(ret) \ - { \ - ERR_EXPLAIN(__ASSERT_SCRIPT_REASON); \ - ERR_FAIL_COND_V(!can_instance(), ret); \ +#define ASSERT_SCRIPT_VALID_V(ret) \ + { \ + ERR_FAIL_COND_V_MSG(!can_instance(), ret, __ASSERT_SCRIPT_REASON); \ } #else #define ASSERT_SCRIPT_VALID() @@ -197,8 +195,7 @@ ScriptInstance *PluginScript::instance_create(Object *p_this) { // if (ScriptDebugger::get_singleton()) { // _language->debug_break_parse(get_path(), 0, msg); // } - ERR_EXPLAIN(msg); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, msg); } } @@ -272,8 +269,7 @@ Error PluginScript::reload(bool p_keep_state) { _ref_base_parent = res; } else { String name = *(StringName *)&manifest.name; - ERR_EXPLAIN(_path + ": Script '" + name + "' has an invalid parent '" + *base_name + "'."); - ERR_FAIL_V(ERR_PARSE_ERROR); + ERR_FAIL_V_MSG(ERR_PARSE_ERROR, _path + ": Script '" + name + "' has an invalid parent '" + *base_name + "'."); } } } @@ -420,8 +416,7 @@ Error PluginScript::load_source_code(const String &p_path) { String s; if (s.parse_utf8((const char *)w.ptr())) { - ERR_EXPLAIN("Script '" + p_path + "' contains invalid unicode (utf-8), so it was not loaded. Please ensure that scripts are saved in valid utf-8 unicode."); - ERR_FAIL_V(ERR_INVALID_DATA); + ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Script '" + p_path + "' contains invalid unicode (UTF-8), so it was not loaded. Please ensure that scripts are saved in valid UTF-8 unicode."); } _source = s; diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index bc28f7009e..d929bdb3e5 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -67,10 +67,7 @@ void GDScriptNativeClass::_bind_methods() { Variant GDScriptNativeClass::_new() { Object *o = instance(); - if (!o) { - ERR_EXPLAIN("Class type: '" + String(name) + "' is not instantiable."); - ERR_FAIL_V(Variant()); - } + ERR_FAIL_COND_V_MSG(!o, Variant(), "Class type: '" + String(name) + "' is not instantiable."); Reference *ref = Object::cast_to<Reference>(o); if (ref) { @@ -158,8 +155,7 @@ Variant GDScript::_new(const Variant **p_args, int p_argcount, Variant::CallErro } else { owner = memnew(Reference); //by default, no base means use reference } - ERR_EXPLAIN("Can't inherit from a virtual class"); - ERR_FAIL_COND_V(!owner, Variant()); + ERR_FAIL_COND_V_MSG(!owner, Variant(), "Can't inherit from a virtual class."); Reference *r = Object::cast_to<Reference>(owner); if (r) { @@ -326,8 +322,7 @@ ScriptInstance *GDScript::instance_create(Object *p_this) { if (ScriptDebugger::get_singleton()) { GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), 0, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); } - ERR_EXPLAIN("Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type '" + p_this->get_class() + "'" + "."); } } @@ -648,10 +643,7 @@ Variant GDScript::call(const StringName &p_method, const Variant **p_args, int p Map<StringName, GDScriptFunction *>::Element *E = top->member_functions.find(p_method); if (E) { - if (!E->get()->is_static()) { - ERR_EXPLAIN("Can't call non-static function: '" + String(p_method) + "' in script."); - ERR_FAIL_V(Variant()); - } + ERR_FAIL_COND_V_MSG(!E->get()->is_static(), Variant(), "Can't call non-static function '" + String(p_method) + "' in script."); return E->get()->call(NULL, p_args, p_argcount, r_error); } @@ -826,8 +818,7 @@ Error GDScript::load_source_code(const String &p_path) { String s; if (s.parse_utf8((const char *)w.ptr())) { - ERR_EXPLAIN("Script '" + p_path + "' contains invalid unicode (utf-8), so it was not loaded. Please ensure that scripts are saved in valid utf-8 unicode."); - ERR_FAIL_V(ERR_INVALID_DATA); + ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Script '" + p_path + "' contains invalid unicode (UTF-8), so it was not loaded. Please ensure that scripts are saved in valid UTF-8 unicode."); } source = s; @@ -1079,11 +1070,8 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const Variant ret = const_cast<GDScriptFunction *>(E->get())->call(const_cast<GDScriptInstance *>(this), NULL, 0, err); if (err.error == Variant::CallError::CALL_OK) { - if (ret.get_type() != Variant::ARRAY) { + ERR_FAIL_COND_MSG(ret.get_type() != Variant::ARRAY, "Wrong type for _get_property_list, must be an array of dictionaries."); - ERR_EXPLAIN("Wrong type for _get_property list, must be an array of dictionaries."); - ERR_FAIL(); - } Array arr = ret; for (int i = 0; i < arr.size(); i++) { @@ -1243,8 +1231,7 @@ String GDScriptInstance::to_string(bool *r_valid) { if (ret.get_type() != Variant::STRING) { if (r_valid) *r_valid = false; - ERR_EXPLAIN("Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); - ERR_FAIL_V(String()); + ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); } if (r_valid) *r_valid = true; @@ -2057,8 +2044,7 @@ String GDScriptWarning::get_message() const { } break; case WARNING_MAX: break; // Can't happen, but silences warning } - ERR_EXPLAIN("Invalid GDScript warning code: " + get_name_from_code(code)); - ERR_FAIL_V(String()); + ERR_FAIL_V_MSG(String(), "Invalid GDScript warning code: " + get_name_from_code(code) + "."); #undef CHECK_SYMBOLS } @@ -2110,8 +2096,7 @@ GDScriptWarning::Code GDScriptWarning::get_code_from_name(const String &p_name) } } - ERR_EXPLAIN("Invalid GDScript warning name: " + p_name); - ERR_FAIL_V(WARNING_MAX); + ERR_FAIL_V_MSG(WARNING_MAX, "Invalid GDScript warning name: " + p_name); } #endif // DEBUG_ENABLED diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 4c976bd2e0..7166189416 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -1241,8 +1241,7 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } break; default: { - ERR_EXPLAIN("Bug in bytecode compiler, unexpected operator #" + itos(on->op) + " in parse tree while parsing expression."); - ERR_FAIL_V(0); //unreachable code + ERR_FAIL_V_MSG(0, "Bug in bytecode compiler, unexpected operator #" + itos(on->op) + " in parse tree while parsing expression."); //unreachable code } break; } @@ -1255,8 +1254,7 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: //TYPE_TYPE, default: { - ERR_EXPLAIN("Bug in bytecode compiler, unexpected node in parse tree while parsing expression."); - ERR_FAIL_V(-1); //unreachable code + ERR_FAIL_V_MSG(-1, "Bug in bytecode compiler, unexpected node in parse tree while parsing expression."); //unreachable code } break; } } diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 42f349ffc0..dc0e64fd03 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -86,8 +86,7 @@ Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_insta o = o->_owner; } - ERR_EXPLAIN("GDScriptCompiler bug..."); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "GDScriptCompiler bug."); } break; case ADDR_TYPE_LOCAL_CONSTANT: { #ifdef DEBUG_ENABLED @@ -128,8 +127,7 @@ Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_insta } break; } - ERR_EXPLAIN("Bad Code! (Addressing Mode)"); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Bad code! (unknown addressing mode)."); return NULL; } @@ -1834,8 +1832,7 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) { ERR_FAIL_COND_V(!function, Variant()); if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) { #ifdef DEBUG_ENABLED - ERR_EXPLAIN("Resumed function '" + String(function->get_name()) + "()' after yield, but class instance is gone. At script: " + state.script->get_path() + ":" + itos(state.line)); - ERR_FAIL_V(Variant()); + ERR_FAIL_V_MSG(Variant(), "Resumed function '" + String(function->get_name()) + "()' after yield, but class instance is gone. At script: " + state.script->get_path() + ":" + itos(state.line)); #else return Variant(); #endif diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index f5f245b25f..ad8bf5b2c0 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -349,8 +349,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); r_ret = Math::step_decimals((double)*p_args[0]); - ERR_EXPLAIN("GDScript method 'decimals' is deprecated and has been renamed to 'step_decimals', please update your code accordingly."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("GDScript method 'decimals' is deprecated and has been renamed to 'step_decimals', please update your code accordingly."); } break; case MATH_STEP_DECIMALS: { VALIDATE_ARG_COUNT(1); diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 357e9c9615..9a25e788c7 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -898,6 +898,10 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } else if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_IS && tokenizer->get_token(1) == GDScriptTokenizer::TK_BUILT_IN_TYPE) { // 'is' operator with built-in type + if (!expr) { + _set_error("Expected identifier before 'is' operator"); + return NULL; + } OperatorNode *op = alloc_node<OperatorNode>(); op->op = OperatorNode::OP_IS_BUILTIN; op->arguments.push_back(expr); @@ -1136,10 +1140,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s return NULL; //nothing } - if (!expr) { - ERR_EXPLAIN("GDScriptParser bug, couldn't figure out what expression is..."); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!expr, NULL, "GDScriptParser bug, couldn't figure out what expression is."); /******************/ /* Parse Indexing */ @@ -4019,8 +4020,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { - ERR_EXPLAIN("Exporting bit flags hint requires string constants."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("Exporting bit flags hint requires string constants."); break; } if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { @@ -6695,8 +6695,7 @@ bool GDScriptParser::_get_function_signature(DataType &p_base_type, const String } if (!ClassDB::class_exists(native)) { if (!check_types) return false; - ERR_EXPLAIN("Parser bug: Class '" + String(native) + "' not found."); - ERR_FAIL_V(false); + ERR_FAIL_V_MSG(false, "Parser bug: Class '" + String(native) + "' not found."); } MethodBind *method = ClassDB::get_method(native, p_function); @@ -7204,8 +7203,7 @@ bool GDScriptParser::_get_member_type(const DataType &p_base_type, const StringN } if (!ClassDB::class_exists(native)) { if (!check_types) return false; - ERR_EXPLAIN("Parser bug: Class '" + String(native) + "' not found."); - ERR_FAIL_V(false); + ERR_FAIL_V_MSG(false, "Parser bug: Class '" + String(native) + "' not found."); } bool valid = false; diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index 59b53b5f9a..64b354bdb8 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -357,8 +357,7 @@ StringName GDScriptTokenizer::get_token_literal(int p_offset) const { } } } - ERR_EXPLAIN("Failed to get token literal"); - ERR_FAIL_V(""); + ERR_FAIL_V_MSG("", "Failed to get token literal."); } static bool _is_text_char(CharType c) { @@ -1219,10 +1218,8 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) ERR_FAIL_COND_V(p_buffer.size() < 24 || p_buffer[0] != 'G' || p_buffer[1] != 'D' || p_buffer[2] != 'S' || p_buffer[3] != 'C', ERR_INVALID_DATA); int version = decode_uint32(&buf[4]); - if (version > BYTECODE_VERSION) { - ERR_EXPLAIN("Bytecode is too New! Please use a newer engine version."); - ERR_FAIL_V(ERR_INVALID_DATA); - } + ERR_FAIL_COND_V_MSG(version > BYTECODE_VERSION, ERR_INVALID_DATA, "Bytecode is too recent! Please use a newer engine version."); + int identifier_count = decode_uint32(&buf[8]); int constant_count = decode_uint32(&buf[12]); int line_count = decode_uint32(&buf[16]); diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index b8a13ed91b..62117dcaf3 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -32,6 +32,7 @@ #include "core/io/file_access_encrypted.h" #include "core/io/resource_loader.h" +#include "core/os/dir_access.h" #include "core/os/file_access.h" #include "editor/gdscript_highlighter.h" #include "gdscript.h" @@ -117,6 +118,9 @@ public: file = FileAccess::get_file_as_array(tmp_path); add_file(p_path.get_basename() + ".gde", file, true); + // Clean up temporary file. + DirAccess::remove_file_or_error(tmp_path); + } else { add_file(p_path.get_basename() + ".gdc", file, true); diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index bdecbbdbad..b36afd4386 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -196,16 +196,14 @@ bool GridMap::get_collision_layer_bit(int p_bit) const { #ifndef DISABLE_DEPRECATED void GridMap::set_theme(const Ref<MeshLibrary> &p_theme) { - ERR_EXPLAIN("GridMap.theme/set_theme() is deprecated and will be removed in a future version. Use GridMap.mesh_library/set_mesh_library() instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("GridMap.theme/set_theme() is deprecated and will be removed in a future version. Use GridMap.mesh_library/set_mesh_library() instead."); set_mesh_library(p_theme); } Ref<MeshLibrary> GridMap::get_theme() const { - ERR_EXPLAIN("GridMap.theme/get_theme() is deprecated and will be removed in a future version. Use GridMap.mesh_library/get_mesh_library() instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("GridMap.theme/get_theme() is deprecated and will be removed in a future version. Use GridMap.mesh_library/get_mesh_library() instead."); return get_mesh_library(); } diff --git a/modules/hdr/image_loader_hdr.cpp b/modules/hdr/image_loader_hdr.cpp index f75a4a926a..e610619b54 100644 --- a/modules/hdr/image_loader_hdr.cpp +++ b/modules/hdr/image_loader_hdr.cpp @@ -102,10 +102,7 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force len <<= 8; len |= f->get_8(); - if (len != width) { - ERR_EXPLAIN("invalid decoded scanline length, corrupt HDR"); - ERR_FAIL_V(ERR_FILE_CORRUPT); - } + ERR_FAIL_COND_V_MSG(len != width, ERR_FILE_CORRUPT, "Invalid decoded scanline length, corrupt HDR."); for (int k = 0; k < 4; ++k) { int i = 0; diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index f8d201b4ca..8c17bac3c9 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -115,7 +115,7 @@ void CSharpLanguage::init() { gdmono->initialize(); #if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) - // Generate bindings here, before loading assemblies. `initialize_load_assemblies` aborts + // Generate bindings here, before loading assemblies. 'initialize_load_assemblies' aborts // the applications if the api assemblies or the main tools assembly is missing, but this // is not a problem for BindingsGenerator as it only needs the tools project editor assembly. List<String> cmdline_args = OS::get_singleton()->get_cmdline_args(); @@ -123,7 +123,7 @@ void CSharpLanguage::init() { #endif #ifndef MONO_GLUE_ENABLED - print_line("Run this binary with `--generate-mono-glue path/to/modules/mono/glue`"); + print_line("Run this binary with '--generate-mono-glue path/to/modules/mono/glue'"); #endif gdmono->initialize_load_assemblies(); @@ -1036,6 +1036,7 @@ void CSharpLanguage::_load_scripts_metadata() { String old_json; Error ferr = read_all_file_utf8(scripts_metadata_path, old_json); + ERR_FAIL_COND(ferr != OK); Variant old_dict_var; @@ -1043,7 +1044,7 @@ void CSharpLanguage::_load_scripts_metadata() { int err_line; Error json_err = JSON::parse(old_json, old_dict_var, err_str, err_line); if (json_err != OK) { - ERR_PRINTS("Failed to parse metadata file: '" + err_str + "' (" + String::num_int64(err_line) + ")"); + ERR_PRINTS("Failed to parse metadata file: '" + err_str + "' (" + String::num_int64(err_line) + ")."); return; } @@ -1053,7 +1054,7 @@ void CSharpLanguage::_load_scripts_metadata() { print_verbose("Successfully loaded scripts metadata"); } else { if (!Engine::get_singleton()->is_editor_hint()) { - ERR_PRINT("Missing scripts metadata file"); + ERR_PRINT("Missing scripts metadata file."); } } } @@ -1768,12 +1769,8 @@ MonoObject *CSharpInstance::_internal_new_managed() { // Search the constructor first, to fail with an error if it's not found before allocating anything else. GDMonoMethod *ctor = script->script_class->get_method(CACHED_STRING_NAME(dotctor), 0); - if (ctor == NULL) { - ERR_PRINTS("Cannot create script instance because the class does not define a parameterless constructor: " + script->get_path()); - - ERR_EXPLAIN("Constructor not found"); - ERR_FAIL_V(NULL); - } + ERR_FAIL_NULL_V_MSG(ctor, NULL, + "Cannot create script instance because the class does not define a parameterless constructor: '" + script->get_path() + "'."); CSharpLanguage::get_singleton()->release_script_gchandle(gchandle); @@ -1792,8 +1789,7 @@ MonoObject *CSharpInstance::_internal_new_managed() { owner = NULL; - ERR_EXPLAIN("Failed to allocate memory for the object"); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Failed to allocate memory for the object."); } // Tie managed to unmanaged @@ -2233,7 +2229,7 @@ bool CSharpScript::_update_exports() { MonoObject *tmp_object = mono_object_new(mono_domain_get(), script_class->get_mono_ptr()); if (!tmp_object) { - ERR_PRINT("Failed to allocate temporary MonoObject"); + ERR_PRINT("Failed to allocate temporary MonoObject."); return false; } @@ -2241,12 +2237,8 @@ bool CSharpScript::_update_exports() { GDMonoMethod *ctor = script_class->get_method(CACHED_STRING_NAME(dotctor), 0); - if (ctor == NULL) { - ERR_PRINTS("Cannot construct temporary MonoObject because the class does not define a parameterless constructor: " + get_path()); - - ERR_EXPLAIN("Constructor not found"); - ERR_FAIL_V(NULL); - } + ERR_FAIL_NULL_V_MSG(ctor, NULL, + "Cannot construct temporary MonoObject because the class does not define a parameterless constructor: '" + get_path() + "'."); MonoException *ctor_exc = NULL; ctor->invoke(tmp_object, NULL, &ctor_exc); @@ -2399,7 +2391,7 @@ bool CSharpScript::_get_signal(GDMonoClass *p_class, GDMonoClass *p_delegate, Ve arg.type = GDMonoMarshal::managed_to_variant_type(types[i]); if (arg.type == Variant::NIL) { - ERR_PRINTS("Unknown type of signal parameter: " + arg.name + " in " + p_class->get_full_name()); + ERR_PRINTS("Unknown type of signal parameter: '" + arg.name + "' in '" + p_class->get_full_name() + "'."); return false; } @@ -2427,7 +2419,7 @@ bool CSharpScript::_get_member_export(IMonoClassMember *p_member, bool p_inspect if (p_member->is_static()) { if (p_member->has_attribute(CACHED_CLASS(ExportAttribute))) - ERR_PRINTS("Cannot export member because it is static: " + MEMBER_FULL_QUALIFIED_NAME(p_member)); + ERR_PRINTS("Cannot export member because it is static: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); return false; } @@ -2450,12 +2442,12 @@ bool CSharpScript::_get_member_export(IMonoClassMember *p_member, bool p_inspect GDMonoProperty *property = static_cast<GDMonoProperty *>(p_member); if (!property->has_getter()) { if (exported) - ERR_PRINTS("Read-only property cannot be exported: " + MEMBER_FULL_QUALIFIED_NAME(p_member)); + ERR_PRINTS("Read-only property cannot be exported: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); return false; } if (!property->has_setter()) { if (exported) - ERR_PRINTS("Write-only property (without getter) cannot be exported: " + MEMBER_FULL_QUALIFIED_NAME(p_member)); + ERR_PRINTS("Write-only property (without getter) cannot be exported: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); return false; } } @@ -2474,16 +2466,15 @@ bool CSharpScript::_get_member_export(IMonoClassMember *p_member, bool p_inspect String hint_string; if (variant_type == Variant::NIL) { - ERR_PRINTS("Unknown exported member type: " + MEMBER_FULL_QUALIFIED_NAME(p_member)); + ERR_PRINTS("Unknown exported member type: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); return false; } int hint_res = _try_get_member_export_hint(p_member, type, variant_type, /* allow_generics: */ true, hint, hint_string); - if (hint_res == -1) { - ERR_EXPLAIN("Error while trying to determine information about the exported member: " + MEMBER_FULL_QUALIFIED_NAME(p_member)); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(hint_res == -1, false, + "Error while trying to determine information about the exported member: '" + + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); if (hint_res == 0) { hint = PropertyHint(CACHED_FIELD(ExportAttribute, hint)->get_int_value(attr)); @@ -2532,17 +2523,11 @@ int CSharpScript::_try_get_member_export_hint(IMonoClassMember *p_member, Manage MonoObject *val_obj = mono_field_get_value_object(mono_domain_get(), field, NULL); - if (val_obj == NULL) { - ERR_EXPLAIN("Failed to get '" + enum_field_name + "' constant enum value"); - ERR_FAIL_V(-1); - } + ERR_FAIL_NULL_V_MSG(val_obj, -1, "Failed to get '" + enum_field_name + "' constant enum value."); bool r_error; uint64_t val = GDMonoUtils::unbox_enum_value(val_obj, enum_basetype, r_error); - if (r_error) { - ERR_EXPLAIN("Failed to unbox '" + enum_field_name + "' constant enum value"); - ERR_FAIL_V(-1); - } + ERR_FAIL_COND_V_MSG(r_error, -1, "Failed to unbox '" + enum_field_name + "' constant enum value."); if (val != (unsigned int)i) { uses_default_values = false; @@ -2577,17 +2562,11 @@ int CSharpScript::_try_get_member_export_hint(IMonoClassMember *p_member, Manage PropertyHint elem_hint = PROPERTY_HINT_NONE; String elem_hint_string; - if (elem_variant_type == Variant::NIL) { - ERR_EXPLAIN("Unknown array element type"); - ERR_FAIL_V(-1); - } + ERR_FAIL_COND_V_MSG(elem_variant_type == Variant::NIL, -1, "Unknown array element type."); int hint_res = _try_get_member_export_hint(p_member, elem_type, elem_variant_type, /* allow_generics: */ false, elem_hint, elem_hint_string); - if (hint_res == -1) { - ERR_EXPLAIN("Error while trying to determine information about the array element type"); - ERR_FAIL_V(-1); - } + ERR_FAIL_COND_V_MSG(hint_res == -1, -1, "Error while trying to determine information about the array element type."); // Format: type/hint:hint_string r_hint_string = itos(elem_variant_type) + "/" + itos(elem_hint) + ":" + elem_hint_string; @@ -2775,7 +2754,7 @@ bool CSharpScript::can_instance() const { "Compile", ProjectSettings::get_singleton()->globalize_path(get_path())); } else { - ERR_PRINTS("Cannot add " + get_path() + " to the C# project because it could not be created."); + ERR_PRINTS("C# project could not be created; cannot add file: '" + get_path() + "'."); } } } @@ -2793,12 +2772,10 @@ bool CSharpScript::can_instance() const { if (extra_cond && !script_class) { if (GDMono::get_singleton()->get_project_assembly() == NULL) { // The project assembly is not loaded - ERR_EXPLAIN("Cannot instance script because the project assembly is not loaded. Script: " + get_path()); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Cannot instance script because the project assembly is not loaded. Script: '" + get_path() + "'."); } else { // The project assembly is loaded, but the class could not found - ERR_EXPLAIN("Cannot instance script because the class '" + name + "' could not be found. Script: " + get_path()); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Cannot instance script because the class '" + name + "' could not be found. Script: '" + get_path() + "'."); } } @@ -2820,14 +2797,12 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg // Search the constructor first, to fail with an error if it's not found before allocating anything else. GDMonoMethod *ctor = script_class->get_method(CACHED_STRING_NAME(dotctor), p_argcount); if (ctor == NULL) { - if (p_argcount == 0) { - String path = get_path(); - ERR_PRINTS("Cannot create script instance. The class '" + script_class->get_full_name() + - "' does not define a parameterless constructor." + (path.empty() ? String() : ". Path: " + path)); - } + ERR_FAIL_COND_V_MSG(p_argcount == 0, NULL, + "Cannot create script instance. The class '" + script_class->get_full_name() + + "' does not define a parameterless constructor." + + (get_path().empty() ? String() : " Path: '" + get_path() + "'.")); - ERR_EXPLAIN("Constructor not found"); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Constructor not found."); } Ref<Reference> ref; @@ -2878,8 +2853,7 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg p_owner->set_script_instance(NULL); r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL; - ERR_EXPLAIN("Failed to allocate memory for the object"); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Failed to allocate memory for the object."); } // Tie managed to unmanaged @@ -2950,8 +2924,8 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) { if (ScriptDebugger::get_singleton()) { CSharpLanguage::get_singleton()->debug_break_parse(get_path(), 0, "Script inherits from native type '" + native_name + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); } - ERR_EXPLAIN("Script inherits from native type '" + native_name + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Script inherits from native type '" + native_name + + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'."); } } @@ -3203,12 +3177,12 @@ int CSharpScript::get_member_line(const StringName &p_member) const { Error CSharpScript::load_source_code(const String &p_path) { Error ferr = read_all_file_utf8(p_path, source); - if (ferr != OK) { - if (ferr == ERR_INVALID_DATA) { - ERR_EXPLAIN("Script '" + p_path + "' contains invalid unicode (utf-8), so it was not loaded. Please ensure that scripts are saved in valid utf-8 unicode."); - } - ERR_FAIL_V(ferr); - } + + ERR_FAIL_COND_V_MSG(ferr != OK, ferr, + ferr == ERR_INVALID_DATA ? + "Script '" + p_path + "' contains invalid unicode (UTF-8), so it was not loaded." + " Please ensure that scripts are saved in valid UTF-8 unicode." : + "Failed to read file: '" + p_path + "'."); #ifdef TOOLS_ENABLED source_changed_cache = true; @@ -3277,8 +3251,7 @@ RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p #ifdef DEBUG_ENABLED // User is responsible for thread attach/detach - ERR_EXPLAIN("Thread is not attached"); - CRASH_COND(mono_domain_get() == NULL); + CRASH_COND_MSG(mono_domain_get() == NULL, "Thread is not attached."); #endif #endif @@ -3345,8 +3318,7 @@ Error ResourceFormatSaverCSharpScript::save(const String &p_path, const RES &p_r "Compile", ProjectSettings::get_singleton()->globalize_path(p_path)); } else { - ERR_PRINTS("Failed to create C# project"); - ERR_PRINTS("Cannot add " + p_path + " to the C# project"); + ERR_PRINTS("C# project could not be created; cannot add file: '" + p_path + "'."); } } #endif diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 45037bf637..1888bb3cb9 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -279,7 +279,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf Vector<String> link_target_parts = link_target.split("."); if (link_target_parts.size() <= 0 || link_target_parts.size() > 2) { - ERR_PRINTS("Invalid reference format: " + tag); + ERR_PRINTS("Invalid reference format: '" + tag + "'."); xml_output.append("<c>"); xml_output.append(tag); @@ -375,7 +375,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf xml_output.append(target_enum_itype.proxy_name); // Includes nesting class if any xml_output.append("\"/>"); } else { - ERR_PRINTS("Cannot resolve enum reference in documentation: " + link_target); + ERR_PRINTS("Cannot resolve enum reference in documentation: '" + link_target + "'."); xml_output.append("<c>"); xml_output.append(link_target); @@ -424,7 +424,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf xml_output.append(target_iconst->proxy_name); xml_output.append("\"/>"); } else { - ERR_PRINTS("Cannot resolve global constant reference in documentation: " + link_target); + ERR_PRINTS("Cannot resolve global constant reference in documentation: '" + link_target + "'."); xml_output.append("<c>"); xml_output.append(link_target); @@ -464,7 +464,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf xml_output.append(target_iconst->proxy_name); xml_output.append("\"/>"); } else { - ERR_PRINTS("Cannot resolve constant reference in documentation: " + link_target); + ERR_PRINTS("Cannot resolve constant reference in documentation: '" + link_target + "'."); xml_output.append("<c>"); xml_output.append(link_target); @@ -534,7 +534,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf xml_output.append(target_itype->proxy_name); xml_output.append("\"/>"); } else { - ERR_PRINTS("Cannot resolve type reference in documentation: " + tag); + ERR_PRINTS("Cannot resolve type reference in documentation: '" + tag + "'."); xml_output.append("<c>"); xml_output.append(tag); @@ -812,7 +812,7 @@ void BindingsGenerator::_generate_global_constants(StringBuilder &p_output) { CRASH_COND(enum_class_name != "Variant"); // Hard-coded... - _log("Declaring global enum `%s` inside static class `%s`\n", enum_proxy_name.utf8().get_data(), enum_class_name.utf8().get_data()); + _log("Declaring global enum '%s' inside static class '%s'\n", enum_proxy_name.utf8().get_data(), enum_class_name.utf8().get_data()); p_output.append("\n" INDENT1 "public static partial class "); p_output.append(enum_class_name); @@ -1083,7 +1083,7 @@ Error BindingsGenerator::generate_cs_api(const String &p_output_dir) { proj_err = generate_cs_core_project(core_proj_dir, core_compile_items); if (proj_err != OK) { - ERR_PRINT("Generation of the Core API C# project failed"); + ERR_PRINT("Generation of the Core API C# project failed."); return proj_err; } @@ -1094,7 +1094,7 @@ Error BindingsGenerator::generate_cs_api(const String &p_output_dir) { proj_err = generate_cs_editor_project(editor_proj_dir, editor_compile_items); if (proj_err != OK) { - ERR_PRINT("Generation of the Editor API C# project failed"); + ERR_PRINT("Generation of the Editor API C# project failed."); return proj_err; } @@ -1112,7 +1112,7 @@ Error BindingsGenerator::generate_cs_api(const String &p_output_dir) { // FIXME: There are some members that hide other inherited members. // - In the case of both members being the same kind, the new one must be declared -// explicitly as `new` to avoid the warning (and we must print a message about it). +// explicitly as 'new' to avoid the warning (and we must print a message about it). // - In the case of both members being of a different kind, then the new one must // be renamed to avoid the name collision (and we must print a warning about it). // - Csc warning e.g.: @@ -1186,7 +1186,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str output.append(obj_types[itype.base_name].proxy_name); output.append("\n"); } else { - ERR_PRINTS("Base type '" + itype.base_name.operator String() + "' does not exist, for class " + itype.name); + ERR_PRINTS("Base type '" + itype.base_name.operator String() + "' does not exist, for class '" + itype.name + "'."); return ERR_INVALID_DATA; } } @@ -1273,11 +1273,9 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str for (const List<PropertyInterface>::Element *E = itype.properties.front(); E; E = E->next()) { const PropertyInterface &iprop = E->get(); Error prop_err = _generate_cs_property(itype, iprop, output); - if (prop_err != OK) { - ERR_EXPLAIN("Failed to generate property '" + iprop.cname.operator String() + - "' for class '" + itype.name + "'"); - ERR_FAIL_V(prop_err); - } + ERR_FAIL_COND_V_MSG(prop_err != OK, prop_err, + "Failed to generate property '" + iprop.cname.operator String() + + "' for class '" + itype.name + "'."); } } @@ -1340,10 +1338,8 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str for (const List<MethodInterface>::Element *E = itype.methods.front(); E; E = E->next()) { const MethodInterface &imethod = E->get(); Error method_err = _generate_cs_method(itype, imethod, method_bind_count, output); - if (method_err != OK) { - ERR_EXPLAIN("Failed to generate method '" + imethod.name + "' for class '" + itype.name + "'"); - ERR_FAIL_V(method_err); - } + ERR_FAIL_COND_V_MSG(method_err != OK, method_err, + "Failed to generate method '" + imethod.name + "' for class '" + itype.name + "'."); } if (itype.is_singleton) { @@ -1626,7 +1622,7 @@ Error BindingsGenerator::_generate_cs_method(const BindingsGenerator::TypeInterf if (p_imethod.is_deprecated) { if (p_imethod.deprecation_message.empty()) - WARN_PRINTS("An empty deprecation message is discouraged. Method: " + p_imethod.proxy_name); + WARN_PRINTS("An empty deprecation message is discouraged. Method: '" + p_imethod.proxy_name + "'."); p_output.append(MEMBER_BEGIN "[Obsolete(\""); p_output.append(p_imethod.deprecation_message); @@ -1708,8 +1704,7 @@ Error BindingsGenerator::_generate_cs_method(const BindingsGenerator::TypeInterf Error BindingsGenerator::generate_glue(const String &p_output_dir) { bool dir_exists = DirAccess::exists(p_output_dir); - ERR_EXPLAIN("The output directory does not exist."); - ERR_FAIL_COND_V(!dir_exists, ERR_FILE_BAD_PATH); + ERR_FAIL_COND_V_MSG(!dir_exists, ERR_FILE_BAD_PATH, "The output directory does not exist."); StringBuilder output; @@ -1742,10 +1737,8 @@ Error BindingsGenerator::generate_glue(const String &p_output_dir) { for (const List<MethodInterface>::Element *E = itype.methods.front(); E; E = E->next()) { const MethodInterface &imethod = E->get(); Error method_err = _generate_glue_method(itype, imethod, output); - if (method_err != OK) { - ERR_EXPLAIN("Failed to generate method '" + imethod.name + "' for class '" + itype.name + "'"); - ERR_FAIL_V(method_err); - } + ERR_FAIL_COND_V_MSG(method_err != OK, method_err, + "Failed to generate method '" + imethod.name + "' for class '" + itype.name + "'."); } if (itype.is_singleton) { @@ -1879,8 +1872,7 @@ Error BindingsGenerator::_save_file(const String &p_path, const StringBuilder &p FileAccessRef file = FileAccess::open(p_path, FileAccess::WRITE); - ERR_EXPLAIN("Cannot open file: " + p_path); - ERR_FAIL_COND_V(!file, ERR_FILE_CANT_WRITE); + ERR_FAIL_COND_V_MSG(!file, ERR_FILE_CANT_WRITE, "Cannot open file: '" + p_path + "'."); file->store_string(p_content.as_string()); file->close(); @@ -2091,7 +2083,7 @@ const BindingsGenerator::TypeInterface *BindingsGenerator::_get_type_or_placehol if (found) return found; - ERR_PRINTS(String() + "Type not found. Creating placeholder: " + p_typeref.cname.operator String()); + ERR_PRINTS(String() + "Type not found. Creating placeholder: '" + p_typeref.cname.operator String() + "'."); const Map<StringName, TypeInterface>::Element *match = placeholder_types.find(p_typeref.cname); @@ -2175,13 +2167,13 @@ void BindingsGenerator::_populate_object_type_interfaces() { } if (!ClassDB::is_class_exposed(type_cname)) { - _log("Ignoring type `%s` because it's not exposed\n", String(type_cname).utf8().get_data()); + _log("Ignoring type '%s' because it's not exposed\n", String(type_cname).utf8().get_data()); class_list.pop_front(); continue; } if (!ClassDB::is_class_enabled(type_cname)) { - _log("Ignoring type `%s` because it's not enabled\n", String(type_cname).utf8().get_data()); + _log("Ignoring type '%s' because it's not enabled\n", String(type_cname).utf8().get_data()); class_list.pop_front(); continue; } @@ -2240,7 +2232,7 @@ void BindingsGenerator::_populate_object_type_interfaces() { // Prevent the property and its enclosing type from sharing the same name if (iprop.proxy_name == itype.proxy_name) { - _log("Name of property `%s` is ambiguous with the name of its enclosing class `%s`. Renaming property to `%s_`\n", + _log("Name of property '%s' is ambiguous with the name of its enclosing class '%s'. Renaming property to '%s_'\n", iprop.proxy_name.utf8().get_data(), itype.proxy_name.utf8().get_data(), iprop.proxy_name.utf8().get_data()); iprop.proxy_name += "_"; @@ -2298,28 +2290,26 @@ void BindingsGenerator::_populate_object_type_interfaces() { imethod.is_vararg = m && m->is_vararg(); if (!m && !imethod.is_virtual) { - if (virtual_method_list.find(method_info)) { - // A virtual method without the virtual flag. This is a special case. - - // There is no method bind, so let's fallback to Godot's object.Call(string, params) - imethod.requires_object_call = true; - - // The method Object.free is registered as a virtual method, but without the virtual flag. - // This is because this method is not supposed to be overridden, but called. - // We assume the return type is void. - imethod.return_type.cname = name_cache.type_void; - - // Actually, more methods like this may be added in the future, - // which could actually will return something different. - // Let's put this to notify us if that ever happens. - if (itype.cname != name_cache.type_Object || imethod.name != "free") { - ERR_PRINTS("Notification: New unexpected virtual non-overridable method found.\n" - "We only expected Object.free, but found " + - itype.name + "." + imethod.name); - } - } else { - ERR_EXPLAIN("Missing MethodBind for non-virtual method: " + itype.name + "." + imethod.name); - ERR_FAIL(); + ERR_FAIL_COND_MSG(!virtual_method_list.find(method_info), + "Missing MethodBind for non-virtual method: '" + itype.name + "." + imethod.name + "'."); + + // A virtual method without the virtual flag. This is a special case. + + // There is no method bind, so let's fallback to Godot's object.Call(string, params) + imethod.requires_object_call = true; + + // The method Object.free is registered as a virtual method, but without the virtual flag. + // This is because this method is not supposed to be overridden, but called. + // We assume the return type is void. + imethod.return_type.cname = name_cache.type_void; + + // Actually, more methods like this may be added in the future, + // which could actually will return something different. + // Let's put this to notify us if that ever happens. + if (itype.cname != name_cache.type_Object || imethod.name != "free") { + ERR_PRINTS("Notification: New unexpected virtual non-overridable method found." + " We only expected Object.free, but found '" + + itype.name + "." + imethod.name + "'."); } } else if (return_info.type == Variant::INT && return_info.usage & PROPERTY_USAGE_CLASS_IS_ENUM) { imethod.return_type.cname = return_info.class_name; @@ -2328,8 +2318,8 @@ void BindingsGenerator::_populate_object_type_interfaces() { imethod.return_type.cname = return_info.class_name; if (!imethod.is_virtual && ClassDB::is_parent_class(return_info.class_name, name_cache.type_Reference) && return_info.hint != PROPERTY_HINT_RESOURCE_TYPE) { /* clang-format off */ - ERR_PRINTS("Return type is reference but hint is not " _STR(PROPERTY_HINT_RESOURCE_TYPE) "." - " Are you returning a reference type by pointer? Method: " + itype.name + "." + imethod.name); + ERR_PRINTS("Return type is reference but hint is not '" _STR(PROPERTY_HINT_RESOURCE_TYPE) "'." + " Are you returning a reference type by pointer? Method: '" + itype.name + "." + imethod.name + "'."); /* clang-format on */ ERR_FAIL(); } @@ -2394,7 +2384,7 @@ void BindingsGenerator::_populate_object_type_interfaces() { // Prevent the method and its enclosing type from sharing the same name if (imethod.proxy_name == itype.proxy_name) { - _log("Name of method `%s` is ambiguous with the name of its enclosing class `%s`. Renaming method to `%s_`\n", + _log("Name of method '%s' is ambiguous with the name of its enclosing class '%s'. Renaming method to '%s_'\n", imethod.proxy_name.utf8().get_data(), itype.proxy_name.utf8().get_data(), imethod.proxy_name.utf8().get_data()); imethod.proxy_name += "_"; @@ -2880,8 +2870,7 @@ void BindingsGenerator::_populate_global_constants() { if (global_constants_count > 0) { Map<String, DocData::ClassDoc>::Element *match = EditorHelp::get_doc_data()->class_list.find("@GlobalScope"); - ERR_EXPLAIN("Could not find `@GlobalScope` in DocData"); - CRASH_COND(!match); + CRASH_COND_MSG(!match, "Could not find '@GlobalScope' in DocData."); const DocData::ClassDoc &global_scope_doc = match->value(); @@ -2935,7 +2924,7 @@ void BindingsGenerator::_populate_global_constants() { // HARDCODED: The Error enum have the prefix 'ERR_' for everything except 'OK' and 'FAILED'. if (ienum.cname == name_cache.enum_Error) { if (prefix_length > 0) { // Just in case it ever changes - ERR_PRINTS("Prefix for enum 'Error' is not empty"); + ERR_PRINTS("Prefix for enum '" _STR(Error) "' is not empty."); } prefix_length = 1; // 'ERR_' @@ -3024,7 +3013,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) glue_dir_path = path_elem->get(); elem = elem->next(); } else { - ERR_PRINTS(generate_all_glue_option + ": No output directory specified (expected path to {GODOT_ROOT}/modules/mono/glue)"); + ERR_PRINTS(generate_all_glue_option + ": No output directory specified (expected path to '{GODOT_ROOT}/modules/mono/glue')."); } --options_left; @@ -3035,7 +3024,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) cs_dir_path = path_elem->get(); elem = elem->next(); } else { - ERR_PRINTS(generate_cs_glue_option + ": No output directory specified"); + ERR_PRINTS(generate_cs_glue_option + ": No output directory specified."); } --options_left; @@ -3046,7 +3035,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) cpp_dir_path = path_elem->get(); elem = elem->next(); } else { - ERR_PRINTS(generate_cpp_glue_option + ": No output directory specified"); + ERR_PRINTS(generate_cpp_glue_option + ": No output directory specified."); } --options_left; @@ -3061,20 +3050,20 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) if (glue_dir_path.length()) { if (bindings_generator.generate_glue(glue_dir_path) != OK) - ERR_PRINTS(generate_all_glue_option + ": Failed to generate the C++ glue"); + ERR_PRINTS(generate_all_glue_option + ": Failed to generate the C++ glue."); if (bindings_generator.generate_cs_api(glue_dir_path.plus_file("Managed/Generated")) != OK) - ERR_PRINTS(generate_all_glue_option + ": Failed to generate the C# API"); + ERR_PRINTS(generate_all_glue_option + ": Failed to generate the C# API."); } if (cs_dir_path.length()) { if (bindings_generator.generate_cs_api(cs_dir_path) != OK) - ERR_PRINTS(generate_cs_glue_option + ": Failed to generate the C# API"); + ERR_PRINTS(generate_cs_glue_option + ": Failed to generate the C# API."); } if (cpp_dir_path.length()) { if (bindings_generator.generate_glue(cpp_dir_path) != OK) - ERR_PRINTS(generate_cpp_glue_option + ": Failed to generate the C++ glue"); + ERR_PRINTS(generate_cpp_glue_option + ": Failed to generate the C++ glue."); } // Exit once done diff --git a/modules/mono/editor/bindings_generator.h b/modules/mono/editor/bindings_generator.h index 8be51a6c55..6f0c297575 100644 --- a/modules/mono/editor/bindings_generator.h +++ b/modules/mono/editor/bindings_generator.h @@ -147,7 +147,7 @@ class BindingsGenerator { bool requires_object_call; /** - * Determines if the method visibility is `internal` (visible only to files in the same assembly). + * Determines if the method visibility is 'internal' (visible only to files in the same assembly). * Currently, we only use this for methods that are not meant to be exposed, * but are required by properties as getters or setters. * Methods that are not meant to be exposed are those that begin with underscore and are not virtual. diff --git a/modules/mono/editor/csharp_project.cpp b/modules/mono/editor/csharp_project.cpp index d88b08c646..0e6c58c9d7 100644 --- a/modules/mono/editor/csharp_project.cpp +++ b/modules/mono/editor/csharp_project.cpp @@ -81,16 +81,14 @@ bool generate_api_solution(const String &p_solution_dir, const String &p_core_pr _GDMONO_SCOPE_DOMAIN_(temp_domain); - GDMonoAssembly *tools_project_editor_assembly = NULL; + GDMonoAssembly *tools_project_editor_asm = NULL; - if (!GDMono::get_singleton()->load_assembly("GodotTools.ProjectEditor", &tools_project_editor_assembly)) { - ERR_EXPLAIN("Failed to load assembly: 'GodotTools.ProjectEditor'"); - ERR_FAIL_V(false); - } + bool assembly_loaded = GDMono::get_singleton()->load_assembly(TOOLS_PROJECT_EDITOR_ASM_NAME, &tools_project_editor_asm); + ERR_FAIL_COND_V_MSG(!assembly_loaded, false, "Failed to load assembly: '" TOOLS_PROJECT_EDITOR_ASM_NAME "'."); return generate_api_solution_impl(p_solution_dir, p_core_proj_dir, p_core_compile_items, p_editor_proj_dir, p_editor_compile_items, - tools_project_editor_assembly); + tools_project_editor_asm); } } diff --git a/modules/mono/editor/godotsharp_export.cpp b/modules/mono/editor/godotsharp_export.cpp index 020bb70a08..80a7335b1d 100644 --- a/modules/mono/editor/godotsharp_export.cpp +++ b/modules/mono/editor/godotsharp_export.cpp @@ -85,18 +85,12 @@ Error GodotSharpExport::get_assembly_dependencies(GDMonoAssembly *p_assembly, co } } - if (!ref_assembly) { - ERR_EXPLAIN("Cannot load assembly (refonly): " + ref_name); - ERR_FAIL_V(ERR_CANT_RESOLVE); - } + ERR_FAIL_COND_V_MSG(!ref_assembly, ERR_CANT_RESOLVE, "Cannot load assembly (refonly): '" + ref_name + "'."); r_dependencies[ref_name] = ref_assembly->get_path(); Error err = get_assembly_dependencies(ref_assembly, p_search_dirs, r_dependencies); - if (err != OK) { - ERR_EXPLAIN("Cannot load one of the dependencies for the assembly: " + ref_name); - ERR_FAIL_V(err); - } + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot load one of the dependencies for the assembly: '" + ref_name + "'."); } return OK; @@ -113,8 +107,7 @@ Error GodotSharpExport::get_exported_assembly_dependencies(const String &p_proje bool load_success = GDMono::get_singleton()->load_assembly_from(p_project_dll_name, p_project_dll_src_path, &scripts_assembly, /* refonly: */ true); - ERR_EXPLAIN("Cannot load assembly (refonly): " + p_project_dll_name); - ERR_FAIL_COND_V(!load_success, ERR_CANT_RESOLVE); + ERR_FAIL_COND_V_MSG(!load_success, ERR_CANT_RESOLVE, "Cannot load assembly (refonly): '" + p_project_dll_name + "'."); Vector<String> search_dirs; GDMonoAssembly::fill_search_dirs(search_dirs, p_build_config, p_custom_lib_dir); diff --git a/modules/mono/editor/script_class_parser.cpp b/modules/mono/editor/script_class_parser.cpp index dfb652a7aa..dcb0ca5a80 100644 --- a/modules/mono/editor/script_class_parser.cpp +++ b/modules/mono/editor/script_class_parser.cpp @@ -162,8 +162,8 @@ ScriptClassParser::Token ScriptClassParser::get_token() { error = true; return TK_ERROR; } else if (code[idx] == begin_str) { - if (verbatim && code[idx + 1] == '"') { // `""` is verbatim string's `\"` - idx += 2; // skip next `"` as well + if (verbatim && code[idx + 1] == '"') { // '""' is verbatim string's '\"' + idx += 2; // skip next '"' as well continue; } @@ -590,7 +590,7 @@ Error ScriptClassParser::parse(const String &p_code) { name = String(value); } else if (tk == TK_CURLY_BRACKET_OPEN) { if (name.empty()) { - error_str = "Expected " + get_token_name(TK_IDENTIFIER) + " after keyword `struct`, found " + get_token_name(TK_CURLY_BRACKET_OPEN); + error_str = "Expected " + get_token_name(TK_IDENTIFIER) + " after keyword 'struct', found " + get_token_name(TK_CURLY_BRACKET_OPEN); error = true; return ERR_PARSE_ERROR; } @@ -657,12 +657,12 @@ Error ScriptClassParser::parse_file(const String &p_filepath) { String source; Error ferr = read_all_file_utf8(p_filepath, source); - if (ferr != OK) { - if (ferr == ERR_INVALID_DATA) { - ERR_EXPLAIN("File '" + p_filepath + "' contains invalid unicode (utf-8), so it was not loaded. Please ensure that scripts are saved in valid utf-8 unicode."); - } - ERR_FAIL_V(ferr); - } + + ERR_FAIL_COND_V_MSG(ferr != OK, ferr, + ferr == ERR_INVALID_DATA ? + "File '" + p_filepath + "' contains invalid unicode (UTF-8), so it was not loaded." + " Please ensure that scripts are saved in valid UTF-8 unicode." : + "Failed to read file: '" + p_filepath + "'."); return parse(source); } diff --git a/modules/mono/glue/Managed/Files/Basis.cs b/modules/mono/glue/Managed/Files/Basis.cs index 421532b68f..0eb76e9c63 100644 --- a/modules/mono/glue/Managed/Files/Basis.cs +++ b/modules/mono/glue/Managed/Files/Basis.cs @@ -12,40 +12,6 @@ namespace Godot [StructLayout(LayoutKind.Sequential)] public struct Basis : IEquatable<Basis> { - private static readonly Basis identity = new Basis - ( - 1f, 0f, 0f, - 0f, 1f, 0f, - 0f, 0f, 1f - ); - - private static readonly Basis[] orthoBases = { - new Basis(1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 1f), - new Basis(0f, -1f, 0f, 1f, 0f, 0f, 0f, 0f, 1f), - new Basis(-1f, 0f, 0f, 0f, -1f, 0f, 0f, 0f, 1f), - new Basis(0f, 1f, 0f, -1f, 0f, 0f, 0f, 0f, 1f), - new Basis(1f, 0f, 0f, 0f, 0f, -1f, 0f, 1f, 0f), - new Basis(0f, 0f, 1f, 1f, 0f, 0f, 0f, 1f, 0f), - new Basis(-1f, 0f, 0f, 0f, 0f, 1f, 0f, 1f, 0f), - new Basis(0f, 0f, -1f, -1f, 0f, 0f, 0f, 1f, 0f), - new Basis(1f, 0f, 0f, 0f, -1f, 0f, 0f, 0f, -1f), - new Basis(0f, 1f, 0f, 1f, 0f, 0f, 0f, 0f, -1f), - new Basis(-1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, -1f), - new Basis(0f, -1f, 0f, -1f, 0f, 0f, 0f, 0f, -1f), - new Basis(1f, 0f, 0f, 0f, 0f, 1f, 0f, -1f, 0f), - new Basis(0f, 0f, -1f, 1f, 0f, 0f, 0f, -1f, 0f), - new Basis(-1f, 0f, 0f, 0f, 0f, -1f, 0f, -1f, 0f), - new Basis(0f, 0f, 1f, -1f, 0f, 0f, 0f, -1f, 0f), - new Basis(0f, 0f, 1f, 0f, 1f, 0f, -1f, 0f, 0f), - new Basis(0f, -1f, 0f, 0f, 0f, 1f, -1f, 0f, 0f), - new Basis(0f, 0f, -1f, 0f, -1f, 0f, -1f, 0f, 0f), - new Basis(0f, 1f, 0f, 0f, 0f, -1f, -1f, 0f, 0f), - new Basis(0f, 0f, 1f, 0f, -1f, 0f, 1f, 0f, 0f), - new Basis(0f, 1f, 0f, 0f, 0f, 1f, 1f, 0f, 0f), - new Basis(0f, 0f, -1f, 0f, 1f, 0f, 1f, 0f, 0f), - new Basis(0f, -1f, 0f, 0f, 0f, -1f, 1f, 0f, 0f) - }; - // NOTE: x, y and z are public-only. Use Column0, Column1 and Column2 internally. /// <summary> @@ -64,7 +30,6 @@ namespace Godot /// </summary> public Vector3 y { - get => Column1; set => Column1 = value; } @@ -75,7 +40,6 @@ namespace Godot /// </summary> public Vector3 z { - get => Column2; set => Column2 = value; } @@ -115,8 +79,6 @@ namespace Godot } } - public static Basis Identity => identity; - public Vector3 Scale { get @@ -361,7 +323,7 @@ namespace Godot for (int i = 0; i < 24; i++) { - if (orthoBases[i] == orth) + if (orth == _orthoBases[i]) return i; } @@ -531,6 +493,43 @@ namespace Godot } } + private static readonly Basis[] _orthoBases = { + new Basis(1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 1f), + new Basis(0f, -1f, 0f, 1f, 0f, 0f, 0f, 0f, 1f), + new Basis(-1f, 0f, 0f, 0f, -1f, 0f, 0f, 0f, 1f), + new Basis(0f, 1f, 0f, -1f, 0f, 0f, 0f, 0f, 1f), + new Basis(1f, 0f, 0f, 0f, 0f, -1f, 0f, 1f, 0f), + new Basis(0f, 0f, 1f, 1f, 0f, 0f, 0f, 1f, 0f), + new Basis(-1f, 0f, 0f, 0f, 0f, 1f, 0f, 1f, 0f), + new Basis(0f, 0f, -1f, -1f, 0f, 0f, 0f, 1f, 0f), + new Basis(1f, 0f, 0f, 0f, -1f, 0f, 0f, 0f, -1f), + new Basis(0f, 1f, 0f, 1f, 0f, 0f, 0f, 0f, -1f), + new Basis(-1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, -1f), + new Basis(0f, -1f, 0f, -1f, 0f, 0f, 0f, 0f, -1f), + new Basis(1f, 0f, 0f, 0f, 0f, 1f, 0f, -1f, 0f), + new Basis(0f, 0f, -1f, 1f, 0f, 0f, 0f, -1f, 0f), + new Basis(-1f, 0f, 0f, 0f, 0f, -1f, 0f, -1f, 0f), + new Basis(0f, 0f, 1f, -1f, 0f, 0f, 0f, -1f, 0f), + new Basis(0f, 0f, 1f, 0f, 1f, 0f, -1f, 0f, 0f), + new Basis(0f, -1f, 0f, 0f, 0f, 1f, -1f, 0f, 0f), + new Basis(0f, 0f, -1f, 0f, -1f, 0f, -1f, 0f, 0f), + new Basis(0f, 1f, 0f, 0f, 0f, -1f, -1f, 0f, 0f), + new Basis(0f, 0f, 1f, 0f, -1f, 0f, 1f, 0f, 0f), + new Basis(0f, 1f, 0f, 0f, 0f, 1f, 1f, 0f, 0f), + new Basis(0f, 0f, -1f, 0f, 1f, 0f, 1f, 0f, 0f), + new Basis(0f, -1f, 0f, 0f, 0f, -1f, 1f, 0f, 0f) + }; + + private static readonly Basis _identity = new Basis(1, 0, 0, 0, 1, 0, 0, 0, 1); + private static readonly Basis _flipX = new Basis(-1, 0, 0, 0, 1, 0, 0, 0, 1); + private static readonly Basis _flipY = new Basis(1, 0, 0, 0, -1, 0, 0, 0, 1); + private static readonly Basis _flipZ = new Basis(1, 0, 0, 0, 1, 0, 0, 0, -1); + + public static Basis Identity { get { return _identity; } } + public static Basis FlipX { get { return _flipX; } } + public static Basis FlipY { get { return _flipY; } } + public static Basis FlipZ { get { return _flipZ; } } + public Basis(Quat quat) { real_t s = 2.0f / quat.LengthSquared; diff --git a/modules/mono/glue/gd_glue.cpp b/modules/mono/glue/gd_glue.cpp index 7c30092855..27fd715f60 100644 --- a/modules/mono/glue/gd_glue.cpp +++ b/modules/mono/glue/gd_glue.cpp @@ -167,7 +167,7 @@ MonoObject *godot_icall_GD_str2var(MonoString *p_str) { int line; Error err = VariantParser::parse(&ss, ret, errs, line); if (err != OK) { - String err_str = "Parse error at line " + itos(line) + ": " + errs; + String err_str = "Parse error at line " + itos(line) + ": " + errs + "."; ERR_PRINTS(err_str); ret = err_str; } @@ -193,8 +193,7 @@ MonoArray *godot_icall_GD_var2bytes(MonoObject *p_var, MonoBoolean p_full_object PoolByteArray barr; int len; Error err = encode_variant(var, NULL, len, p_full_objects); - ERR_EXPLAIN("Unexpected error encoding variable to bytes, likely unserializable type found (Object or RID)."); - ERR_FAIL_COND_V(err != OK, NULL); + ERR_FAIL_COND_V_MSG(err != OK, NULL, "Unexpected error encoding variable to bytes, likely unserializable type found (Object or RID)."); barr.resize(len); { diff --git a/modules/mono/godotsharp_defs.h b/modules/mono/godotsharp_defs.h index 4ad4088514..4c17a6ec9d 100644 --- a/modules/mono/godotsharp_defs.h +++ b/modules/mono/godotsharp_defs.h @@ -39,8 +39,8 @@ #define API_SOLUTION_NAME "GodotSharp" #define CORE_API_ASSEMBLY_NAME "GodotSharp" #define EDITOR_API_ASSEMBLY_NAME "GodotSharpEditor" -#define TOOLS_ASSEMBLY_NAME "GodotTools" -#define TOOLS_PROJECT_EDITOR_ASSEMBLY_NAME "GodotTools.ProjectEditor" +#define TOOLS_ASM_NAME "GodotTools" +#define TOOLS_PROJECT_EDITOR_ASM_NAME "GodotTools.ProjectEditor" #define BINDINGS_CLASS_NATIVECALLS "NativeCalls" #define BINDINGS_CLASS_NATIVECALLS_EDITOR "EditorNativeCalls" diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp index 45f79074be..ee1ecf3be7 100644 --- a/modules/mono/mono_gd/gd_mono.cpp +++ b/modules/mono/mono_gd/gd_mono.cpp @@ -265,7 +265,7 @@ void GDMono::initialize() { #ifdef WINDOWS_ENABLED if (assembly_rootdir.empty() || config_dir.empty()) { - ERR_PRINT("Cannot find Mono in the registry"); + ERR_PRINT("Cannot find Mono in the registry."); // Assertion: if they are not set, then they weren't found in the registry CRASH_COND(mono_reg_info.assembly_dir.length() > 0 || mono_reg_info.config_dir.length() > 0); } @@ -318,9 +318,7 @@ void GDMono::initialize() { #endif root_domain = mono_jit_init_version("GodotEngine.RootDomain", "v4.0.30319"); - - ERR_EXPLAIN("Mono: Failed to initialize runtime"); - ERR_FAIL_NULL(root_domain); + ERR_FAIL_NULL_MSG(root_domain, "Mono: Failed to initialize runtime."); GDMonoUtils::set_main_thread(GDMonoUtils::get_current_thread()); @@ -331,11 +329,11 @@ void GDMono::initialize() { print_verbose("Mono: Runtime initialized"); // mscorlib assembly MUST be present at initialization - ERR_EXPLAIN("Mono: Failed to load mscorlib assembly"); - ERR_FAIL_COND(!_load_corlib_assembly()); + bool corlib_loaded = _load_corlib_assembly(); + ERR_FAIL_COND_MSG(!corlib_loaded, "Mono: Failed to load mscorlib assembly."); - ERR_EXPLAIN("Mono: Failed to load scripts domain"); - ERR_FAIL_COND(_load_scripts_domain() != OK); + Error domain_load_err = _load_scripts_domain(); + ERR_FAIL_COND_MSG(domain_load_err != OK, "Mono: Failed to load scripts domain."); #ifdef DEBUG_ENABLED bool debugger_attached = _wait_for_debugger_msecs(500); @@ -351,8 +349,7 @@ void GDMono::initialize() { void GDMono::initialize_load_assemblies() { #ifndef MONO_GLUE_ENABLED - ERR_EXPLAIN("Mono: This binary was built with `mono_glue=no`; cannot load assemblies"); - CRASH_NOW(); + CRASH_NOW_MSG("Mono: This binary was built with 'mono_glue=no'; cannot load assemblies."); #endif // Load assemblies. The API and tools assemblies are required, @@ -361,10 +358,8 @@ void GDMono::initialize_load_assemblies() { _load_api_assemblies(); #if defined(TOOLS_ENABLED) - if (!_load_tools_assemblies()) { - ERR_EXPLAIN("Mono: Failed to load GodotTools assemblies"); - CRASH_NOW(); - } + bool tool_assemblies_loaded = _load_tools_assemblies(); + CRASH_COND_MSG(!tool_assemblies_loaded, "Mono: Failed to load '" TOOLS_ASM_NAME "' assemblies."); #endif // Load the project's main assembly. This doesn't necessarily need to succeed. @@ -428,12 +423,12 @@ void GDMono::_initialize_and_check_api_hashes() { #ifdef MONO_GLUE_ENABLED if (get_api_core_hash() != GodotSharpBindings::get_core_api_hash()) { - ERR_PRINT("Mono: Core API hash mismatch!"); + ERR_PRINT("Mono: Core API hash mismatch."); } #ifdef TOOLS_ENABLED if (get_api_editor_hash() != GodotSharpBindings::get_editor_api_hash()) { - ERR_PRINT("Mono: Editor API hash mismatch!"); + ERR_PRINT("Mono: Editor API hash mismatch."); } #endif // TOOLS_ENABLED #endif // MONO_GLUE_ENABLED @@ -579,7 +574,7 @@ bool GDMono::copy_prebuilt_api_assembly(APIAssembly::Type p_api_type) { memdelete(da); if (err != OK) { - ERR_PRINTS("Failed to create destination directory for the API assemblies. Error: " + itos(err)); + ERR_PRINTS("Failed to create destination directory for the API assemblies. Error: " + itos(err) + "."); return false; } } @@ -593,16 +588,16 @@ bool GDMono::copy_prebuilt_api_assembly(APIAssembly::Type p_api_type) { String xml_file = assembly_name + ".xml"; if (da->copy(src_dir.plus_file(xml_file), dst_dir.plus_file(xml_file)) != OK) - WARN_PRINTS("Failed to copy " + xml_file); + WARN_PRINTS("Failed to copy '" + xml_file + "'."); String pdb_file = assembly_name + ".pdb"; if (da->copy(src_dir.plus_file(pdb_file), dst_dir.plus_file(pdb_file)) != OK) - WARN_PRINTS("Failed to copy " + pdb_file); + WARN_PRINTS("Failed to copy '" + pdb_file + "'."); Error err = da->copy(assembly_src, assembly_dst); if (err != OK) { - ERR_PRINTS("Failed to copy " + assembly_file); + ERR_PRINTS("Failed to copy '" + assembly_file + "'."); return false; } @@ -617,11 +612,11 @@ String GDMono::update_api_assemblies_from_prebuilt() { #define FAIL_REASON(m_out_of_sync, m_prebuilt_exists) \ ( \ (m_out_of_sync ? \ - String("The assembly is invalidated") : \ - String("The assembly was not found")) + \ + String("The assembly is invalidated ") : \ + String("The assembly was not found ")) + \ (m_prebuilt_exists ? \ - String(" and the prebuilt assemblies are missing") : \ - String(" and we failed to copy the prebuilt assemblies"))) + String("and the prebuilt assemblies are missing.") : \ + String("and we failed to copy the prebuilt assemblies."))) bool api_assembly_out_of_sync = core_api_assembly_out_of_sync || editor_api_assembly_out_of_sync; @@ -755,29 +750,19 @@ void GDMono::_load_api_assemblies() { // update them from the prebuilt assemblies directory before trying to load them. // Shouldn't happen. The project manager loads the prebuilt API assemblies - if (Main::is_project_manager()) { - ERR_EXPLAIN("Failed to load one of the prebuilt API assemblies"); - CRASH_NOW(); - } + CRASH_COND_MSG(Main::is_project_manager(), "Failed to load one of the prebuilt API assemblies."); // 1. Unload the scripts domain - if (_unload_scripts_domain() != OK) { - ERR_EXPLAIN("Mono: Failed to unload scripts domain"); - CRASH_NOW(); - } + Error domain_unload_err = _unload_scripts_domain(); + CRASH_COND_MSG(domain_unload_err != OK, "Mono: Failed to unload scripts domain."); // 2. Update the API assemblies String update_error = update_api_assemblies_from_prebuilt(); - if (!update_error.empty()) { - ERR_EXPLAIN(update_error); - CRASH_NOW(); - } + CRASH_COND_MSG(!update_error.empty(), update_error); // 3. Load the scripts domain again - if (_load_scripts_domain() != OK) { - ERR_EXPLAIN("Mono: Failed to load scripts domain"); - CRASH_NOW(); - } + Error domain_load_err = _load_scripts_domain(); + CRASH_COND_MSG(domain_load_err != OK, "Mono: Failed to load scripts domain."); // 4. Try loading the updated assemblies if (!_try_load_api_assemblies()) { @@ -785,24 +770,22 @@ void GDMono::_load_api_assemblies() { if (_are_api_assemblies_out_of_sync()) { if (core_api_assembly_out_of_sync) { - ERR_PRINT("The assembly '" CORE_API_ASSEMBLY_NAME "' is out of sync"); + ERR_PRINT("The assembly '" CORE_API_ASSEMBLY_NAME "' is out of sync."); } else if (!GDMonoUtils::mono_cache.godot_api_cache_updated) { - ERR_PRINT("The loaded assembly '" CORE_API_ASSEMBLY_NAME "' is in sync, but the cache update failed"); + ERR_PRINT("The loaded assembly '" CORE_API_ASSEMBLY_NAME "' is in sync, but the cache update failed."); } if (editor_api_assembly_out_of_sync) { - ERR_PRINT("The assembly '" EDITOR_API_ASSEMBLY_NAME "' is out of sync"); + ERR_PRINT("The assembly '" EDITOR_API_ASSEMBLY_NAME "' is out of sync."); } CRASH_NOW(); } else { - ERR_EXPLAIN("Failed to load one of the API assemblies"); - CRASH_NOW(); + CRASH_NOW_MSG("Failed to load one of the API assemblies."); } } #else - ERR_EXPLAIN("Failed to load one of the API assemblies"); - CRASH_NOW(); + CRASH_NOW_MSG("Failed to load one of the API assemblies."); #endif } } @@ -813,8 +796,8 @@ bool GDMono::_load_tools_assemblies() { if (tools_assembly && tools_project_editor_assembly) return true; - bool success = load_assembly(TOOLS_ASSEMBLY_NAME, &tools_assembly) && - load_assembly(TOOLS_PROJECT_EDITOR_ASSEMBLY_NAME, &tools_project_editor_assembly); + bool success = load_assembly(TOOLS_ASM_NAME, &tools_assembly) && + load_assembly(TOOLS_PROJECT_EDITOR_ASM_NAME, &tools_project_editor_assembly); return success; } @@ -851,7 +834,7 @@ void GDMono::_install_trace_listener() { (DebuggingUtils_InstallTraceListener)debug_utils->get_method_thunk("InstallTraceListener"); install_func((MonoObject **)&exc); if (exc) { - ERR_PRINT("Failed to install System.Diagnostics.Trace listener"); + ERR_PRINT("Failed to install 'System.Diagnostics.Trace' listener."); GDMonoUtils::debug_print_unhandled_exception(exc); } #endif @@ -865,8 +848,7 @@ Error GDMono::_load_scripts_domain() { scripts_domain = GDMonoUtils::create_domain("GodotEngine.ScriptsDomain"); - ERR_EXPLAIN("Mono: Could not create scripts app domain"); - ERR_FAIL_NULL_V(scripts_domain, ERR_CANT_CREATE); + ERR_FAIL_NULL_V_MSG(scripts_domain, ERR_CANT_CREATE, "Mono: Could not create scripts app domain."); mono_domain_set(scripts_domain, true); @@ -885,7 +867,7 @@ Error GDMono::_unload_scripts_domain() { finalizing_scripts_domain = true; if (!mono_domain_finalize(scripts_domain, 2000)) { - ERR_PRINT("Mono: Domain finalization timeout"); + ERR_PRINT("Mono: Domain finalization timeout."); } finalizing_scripts_domain = false; @@ -911,7 +893,7 @@ Error GDMono::_unload_scripts_domain() { mono_domain_try_unload(domain, (MonoObject **)&exc); if (exc) { - ERR_PRINT("Exception thrown when unloading scripts domain"); + ERR_PRINT("Exception thrown when unloading scripts domain."); GDMonoUtils::debug_unhandled_exception(exc); return FAILED; } @@ -925,20 +907,14 @@ Error GDMono::reload_scripts_domain() { ERR_FAIL_COND_V(!runtime_initialized, ERR_BUG); if (scripts_domain) { - Error err = _unload_scripts_domain(); - if (err != OK) { - ERR_PRINT("Mono: Failed to unload scripts domain"); - return err; - } + Error domain_unload_err = _unload_scripts_domain(); + ERR_FAIL_COND_V_MSG(domain_unload_err != OK, domain_unload_err, "Mono: Failed to unload scripts domain."); } CSharpLanguage::get_singleton()->_on_scripts_domain_unloaded(); - Error err = _load_scripts_domain(); - if (err != OK) { - ERR_PRINT("Mono: Failed to load scripts domain"); - return err; - } + Error domain_load_err = _load_scripts_domain(); + ERR_FAIL_COND_V_MSG(domain_load_err != OK, domain_load_err, "Mono: Failed to load scripts domain."); // Load assemblies. The API and tools assemblies are required, // the application is aborted if these assemblies cannot be loaded. @@ -946,10 +922,8 @@ Error GDMono::reload_scripts_domain() { _load_api_assemblies(); #if defined(TOOLS_ENABLED) - if (!_load_tools_assemblies()) { - ERR_EXPLAIN("Mono: Failed to load GodotTools assemblies"); - CRASH_NOW(); - } + bool tools_assemblies_loaded = _load_tools_assemblies(); + CRASH_COND_MSG(!tools_assemblies_loaded, "Mono: Failed to load '" TOOLS_ASM_NAME "' assemblies."); #endif // Load the project's main assembly. Here, during hot-reloading, we do @@ -971,13 +945,13 @@ Error GDMono::finalize_and_unload_domain(MonoDomain *p_domain) { String domain_name = mono_domain_get_friendly_name(p_domain); - print_verbose("Mono: Unloading domain `" + domain_name + "`..."); + print_verbose("Mono: Unloading domain '" + domain_name + "'..."); if (mono_domain_get() == p_domain) mono_domain_set(root_domain, true); if (!mono_domain_finalize(p_domain, 2000)) { - ERR_PRINT("Mono: Domain finalization timeout"); + ERR_PRINT("Mono: Domain finalization timeout."); } mono_gc_collect(mono_gc_max_generation()); @@ -988,7 +962,7 @@ Error GDMono::finalize_and_unload_domain(MonoDomain *p_domain) { mono_domain_try_unload(p_domain, (MonoObject **)&exc); if (exc) { - ERR_PRINTS("Exception thrown when unloading domain `" + domain_name + "`"); + ERR_PRINTS("Exception thrown when unloading domain '" + domain_name + "'."); GDMonoUtils::debug_print_unhandled_exception(exc); return FAILED; } @@ -1105,7 +1079,7 @@ GDMono::~GDMono() { if (scripts_domain) { Error err = _unload_scripts_domain(); if (err != OK) { - ERR_PRINT("Mono: Failed to unload scripts domain"); + ERR_PRINT("Mono: Failed to unload scripts domain."); } } diff --git a/modules/mono/mono_gd/gd_mono_assembly.cpp b/modules/mono/mono_gd/gd_mono_assembly.cpp index 761c7f6fcb..a82bb42731 100644 --- a/modules/mono/mono_gd/gd_mono_assembly.cpp +++ b/modules/mono/mono_gd/gd_mono_assembly.cpp @@ -151,14 +151,14 @@ MonoAssembly *GDMonoAssembly::_preload_hook(MonoAssemblyName *aname, char **, vo } { - // If we find the assembly here, we load it with `mono_assembly_load_from_full`, + // If we find the assembly here, we load it with 'mono_assembly_load_from_full', // which in turn invokes load hooks before returning the MonoAssembly to us. - // One of the load hooks is `load_aot_module`. This hook can end up calling preload hooks - // again for the same assembly in certain in certain circumstances (the `do_load_image` part). + // One of the load hooks is 'load_aot_module'. This hook can end up calling preload hooks + // again for the same assembly in certain in certain circumstances (the 'do_load_image' part). // If this is the case and we return NULL due to the no_search condition below, // it will result in an internal crash later on. Therefore we need to return the assembly we didn't - // get yet from `mono_assembly_load_from_full`. Luckily we have the image, which already got it. - // This must be done here. If done in search hooks, it would cause `mono_assembly_load_from_full` + // get yet from 'mono_assembly_load_from_full'. Luckily we have the image, which already got it. + // This must be done here. If done in search hooks, it would cause 'mono_assembly_load_from_full' // to think another MonoAssembly for this assembly was already loaded, making it delete its own, // when in fact both pointers were the same... This hooks thing is confusing. if (image_corlib_loading) { diff --git a/modules/mono/mono_gd/gd_mono_class.cpp b/modules/mono/mono_gd/gd_mono_class.cpp index 1c10d3c8eb..89a88fcfb2 100644 --- a/modules/mono/mono_gd/gd_mono_class.cpp +++ b/modules/mono/mono_gd/gd_mono_class.cpp @@ -165,8 +165,8 @@ void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base #ifdef DEBUG_ENABLED String fullname = method->get_ret_type_full_name() + " " + name + "(" + method->get_signature_desc(true) + ")"; - WARN_PRINTS("Method `" + fullname + "` is hidden by Godot API method. Should be `" + - method->get_full_name_no_class() + "`. In class `" + namespace_name + "." + class_name + "`."); + WARN_PRINTS("Method '" + fullname + "' is hidden by Godot API method. Should be '" + + method->get_full_name_no_class() + "'. In class '" + namespace_name + "." + class_name + "'."); #endif continue; } @@ -184,8 +184,8 @@ void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base if (m && m->get_name() != name) { // found String fullname = m->get_ret_type_full_name() + " " + name + "(" + m->get_signature_desc(true) + ")"; - WARN_PRINTS("Method `" + fullname + "` should be `" + m->get_full_name_no_class() + - "`. In class `" + namespace_name + "." + class_name + "`."); + WARN_PRINTS("Method '" + fullname + "' should be '" + m->get_full_name_no_class() + + "'. In class '" + namespace_name + "." + class_name + "'."); break; } diff --git a/modules/mono/mono_gd/gd_mono_field.cpp b/modules/mono/mono_gd/gd_mono_field.cpp index 3999658f93..7b8e6f89e9 100644 --- a/modules/mono/mono_gd/gd_mono_field.cpp +++ b/modules/mono/mono_gd/gd_mono_field.cpp @@ -219,16 +219,14 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_ break; } default: { - ERR_EXPLAIN(String() + "Attempted to convert Variant to a managed enum value of unmarshallable base type."); - ERR_FAIL(); + ERR_FAIL_MSG("Attempted to convert Variant to a managed enum value of unmarshallable base type."); } } break; } - ERR_EXPLAIN(String() + "Attempted to set the value of a field of unmarshallable type: " + tclass->get_name()); - ERR_FAIL(); + ERR_FAIL_MSG("Attempted to set the value of a field of unmarshallable type: '" + tclass->get_name() + "'."); } break; case MONO_TYPE_ARRAY: @@ -275,8 +273,7 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_ break; } - ERR_EXPLAIN(String() + "Attempted to convert Variant to a managed array of unmarshallable element type."); - ERR_FAIL(); + ERR_FAIL_MSG("Attempted to convert Variant to a managed array of unmarshallable element type."); } break; case MONO_TYPE_CLASS: { @@ -351,8 +348,7 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_ } } - ERR_EXPLAIN(String() + "Attempted to set the value of a field of unmarshallable type: " + type_class->get_name()); - ERR_FAIL(); + ERR_FAIL_MSG("Attempted to set the value of a field of unmarshallable type: '" + type_class->get_name() + "'."); } break; case MONO_TYPE_OBJECT: { @@ -508,7 +504,7 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_ } break; default: { - ERR_PRINTS(String() + "Attempted to set the value of a field of unexpected type encoding: " + itos(type.type_encoding)); + ERR_PRINTS("Attempted to set the value of a field of unexpected type encoding: " + itos(type.type_encoding) + "."); } break; } diff --git a/modules/mono/mono_gd/gd_mono_internals.cpp b/modules/mono/mono_gd/gd_mono_internals.cpp index e50e3b0794..3324ecb3a8 100644 --- a/modules/mono/mono_gd/gd_mono_internals.cpp +++ b/modules/mono/mono_gd/gd_mono_internals.cpp @@ -48,7 +48,7 @@ void tie_managed_to_unmanaged(MonoObject *managed, Object *unmanaged) { CRASH_COND(!unmanaged); - // All mono objects created from the managed world (e.g.: `new Player()`) + // All mono objects created from the managed world (e.g.: 'new Player()') // need to have a CSharpScript in order for their methods to be callable from the unmanaged side Reference *ref = Object::cast_to<Reference>(unmanaged); diff --git a/modules/mono/mono_gd/gd_mono_log.cpp b/modules/mono/mono_gd/gd_mono_log.cpp index a6e04e561d..5a0d728953 100644 --- a/modules/mono/mono_gd/gd_mono_log.cpp +++ b/modules/mono/mono_gd/gd_mono_log.cpp @@ -72,7 +72,7 @@ static void mono_log_callback(const char *log_domain, const char *log_level, con } if (fatal) { - ERR_PRINTS("Mono: FATAL ERROR, ABORTING! Logfile: " + GDMonoLog::get_singleton()->get_log_file_path() + "\n"); + ERR_PRINTS("Mono: FATAL ERROR, ABORTING! Logfile: '" + GDMonoLog::get_singleton()->get_log_file_path() + "'."); // Make sure to flush before aborting f->flush(); f->close(); @@ -90,8 +90,7 @@ bool GDMonoLog::_try_create_logs_dir(const String &p_logs_dir) { DirAccessRef diraccess = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); ERR_FAIL_COND_V(!diraccess, false); Error logs_mkdir_err = diraccess->make_dir_recursive(p_logs_dir); - ERR_EXPLAIN("Failed to create mono logs directory"); - ERR_FAIL_COND_V(logs_mkdir_err != OK, false); + ERR_FAIL_COND_V_MSG(logs_mkdir_err != OK, false, "Failed to create mono logs directory."); } return true; @@ -131,7 +130,7 @@ void GDMonoLog::initialize() { CharString log_level = OS::get_singleton()->get_environment("GODOT_MONO_LOG_LEVEL").utf8(); if (log_level.length() != 0 && log_level_get_id(log_level.get_data()) == -1) { - ERR_PRINTS(String() + "Mono: Ignoring invalid log level (GODOT_MONO_LOG_LEVEL): " + log_level.get_data()); + ERR_PRINTS(String() + "Mono: Ignoring invalid log level (GODOT_MONO_LOG_LEVEL): '" + log_level.get_data() + "'."); log_level = CharString(); } @@ -160,7 +159,7 @@ void GDMonoLog::initialize() { log_file = FileAccess::open(log_file_path, FileAccess::WRITE); if (!log_file) { - ERR_PRINT("Mono: Cannot create log file"); + ERR_PRINT("Mono: Cannot create log file."); } } diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index 42102ed835..7aac691102 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -276,7 +276,7 @@ String mono_to_utf8_string(MonoString *p_mono_string) { char *utf8 = mono_string_to_utf8_checked(p_mono_string, &error); if (!mono_error_ok(&error)) { - ERR_PRINTS(String("Failed to convert MonoString* to UTF-8: ") + mono_error_get_message(&error)); + ERR_PRINTS(String() + "Failed to convert MonoString* to UTF-8: '" + mono_error_get_message(&error) + "'."); mono_error_cleanup(&error); return String(); } @@ -474,8 +474,7 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty return BOX_ENUM(enum_baseclass, val); } default: { - ERR_EXPLAIN(String() + "Attempted to convert Variant to a managed enum value of unmarshallable base type."); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Attempted to convert Variant to a managed enum value of unmarshallable base type."); } } } @@ -509,8 +508,7 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty if (array_type->eklass == CACHED_CLASS_RAW(Color)) return (MonoObject *)PoolColorArray_to_mono_array(p_var->operator PoolColorArray()); - ERR_EXPLAIN(String() + "Attempted to convert Variant to a managed array of unmarshallable element type."); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Attempted to convert Variant to a managed array of unmarshallable element type."); } break; case MONO_TYPE_CLASS: { @@ -695,9 +693,8 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty } break; } - ERR_EXPLAIN(String() + "Attempted to convert Variant to an unmarshallable managed type. Name: \'" + - p_type.type_class->get_name() + "\' Encoding: " + itos(p_type.type_encoding)); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Attempted to convert Variant to an unmarshallable managed type. Name: '" + + p_type.type_class->get_name() + "' Encoding: " + itos(p_type.type_encoding) + "."); } Variant mono_object_to_variant(MonoObject *p_obj) { @@ -809,8 +806,7 @@ Variant mono_object_to_variant(MonoObject *p_obj) { if (array_type->eklass == CACHED_CLASS_RAW(Color)) return mono_array_to_PoolColorArray((MonoArray *)p_obj); - ERR_EXPLAIN(String() + "Attempted to convert a managed array of unmarshallable element type to Variant."); - ERR_FAIL_V(Variant()); + ERR_FAIL_V_MSG(Variant(), "Attempted to convert a managed array of unmarshallable element type to Variant."); } break; case MONO_TYPE_CLASS: { @@ -908,9 +904,8 @@ Variant mono_object_to_variant(MonoObject *p_obj) { } break; } - ERR_EXPLAIN(String() + "Attempted to convert an unmarshallable managed type to Variant. Name: \'" + - type.type_class->get_name() + "\' Encoding: " + itos(type.type_encoding)); - ERR_FAIL_V(Variant()); + ERR_FAIL_V_MSG(Variant(), "Attempted to convert an unmarshallable managed type to Variant. Name: '" + + type.type_class->get_name() + "' Encoding: " + itos(type.type_encoding) + "."); } MonoArray *Array_to_mono_array(const Array &p_array) { diff --git a/modules/mono/mono_gd/gd_mono_utils.cpp b/modules/mono/mono_gd/gd_mono_utils.cpp index 7afdfc8ac8..e385f4c601 100644 --- a/modules/mono/mono_gd/gd_mono_utils.cpp +++ b/modules/mono/mono_gd/gd_mono_utils.cpp @@ -52,14 +52,11 @@ namespace GDMonoUtils { MonoCache mono_cache; -#define CACHE_AND_CHECK(m_var, m_val) \ - { \ - CRASH_COND(m_var != NULL); \ - m_var = m_val; \ - if (!m_var) { \ - ERR_EXPLAIN("Mono Cache: Member " #m_var " is null"); \ - ERR_FAIL(); \ - } \ +#define CACHE_AND_CHECK(m_var, m_val) \ + { \ + CRASH_COND(m_var != NULL); \ + m_var = m_val; \ + ERR_FAIL_COND_MSG(!m_var, "Mono Cache: Member " #m_var " is null."); \ } #define CACHE_CLASS_AND_CHECK(m_class, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.class_##m_class, m_val) @@ -453,10 +450,9 @@ GDMonoClass *get_class_native_base(GDMonoClass *p_class) { } MonoObject *create_managed_for_godot_object(GDMonoClass *p_class, const StringName &p_native, Object *p_object) { - if (!ClassDB::is_parent_class(p_object->get_class_name(), p_native)) { - ERR_EXPLAIN("Type inherits from native type '" + p_native + "', so it can't be instanced in object of type: '" + p_object->get_class() + "'"); - ERR_FAIL_V(NULL); - } + bool parent_is_object_class = ClassDB::is_parent_class(p_object->get_class_name(), p_native); + ERR_FAIL_COND_V_MSG(!parent_is_object_class, NULL, + "Type inherits from native type '" + p_native + "', so it can't be instanced in object of type: '" + p_object->get_class() + "'."); MonoObject *mono_object = mono_object_new(mono_domain_get(), p_class->get_mono_ptr()); ERR_FAIL_NULL_V(mono_object, NULL); diff --git a/modules/mono/signal_awaiter_utils.cpp b/modules/mono/signal_awaiter_utils.cpp index 54d73c971f..189ceaab1b 100644 --- a/modules/mono/signal_awaiter_utils.cpp +++ b/modules/mono/signal_awaiter_utils.cpp @@ -67,10 +67,8 @@ Error connect_signal_awaiter(Object *p_source, const String &p_signal, Object *p Variant SignalAwaiterHandle::_signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { #ifdef DEBUG_ENABLED - if (conn_target_id && !ObjectDB::get_instance(conn_target_id)) { - ERR_EXPLAIN("Resumed after await, but class instance is gone"); - ERR_FAIL_V(Variant()); - } + ERR_FAIL_COND_V_MSG(conn_target_id && !ObjectDB::get_instance(conn_target_id), Variant(), + "Resumed after await, but class instance is gone."); #endif if (p_argcount < 1) { diff --git a/modules/mono/utils/string_utils.cpp b/modules/mono/utils/string_utils.cpp index 2b014c2a45..ae5a2cde81 100644 --- a/modules/mono/utils/string_utils.cpp +++ b/modules/mono/utils/string_utils.cpp @@ -55,10 +55,7 @@ int sfind(const String &p_text, int p_from) { for (int j = 0; j < src_len; j++) { int read_pos = i + j; - if (read_pos >= len) { - ERR_PRINT("read_pos >= len"); - return -1; - }; + ERR_FAIL_COND_V(read_pos >= len, -1); switch (j) { case 0: diff --git a/modules/opus/audio_stream_opus.cpp b/modules/opus/audio_stream_opus.cpp index 615081d818..d3e8d3c9bb 100644 --- a/modules/opus/audio_stream_opus.cpp +++ b/modules/opus/audio_stream_opus.cpp @@ -287,8 +287,7 @@ int AudioStreamPlaybackOpus::mix(int16_t *p_buffer, int p_frames) { int ret = op_read(opus_file, (opus_int16 *)p_buffer, todo * stream_channels, ¤t_section); if (ret < 0) { playing = false; - ERR_EXPLAIN("Error reading Opus File: " + file); - ERR_BREAK(ret < 0); + ERR_BREAK_MSG(ret < 0, "Error reading Opus file: " + file + "."); } else if (ret == 0) { // end of song, reload? op_free(opus_file); diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index 8b1f21d95d..cf6b396180 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -149,8 +149,7 @@ RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, format = Image::FORMAT_ETC; break; default: - ERR_EXPLAIN("Unsupported format in PVR texture: " + itos(flags & 0xFF)); - ERR_FAIL_V(RES()); + ERR_FAIL_V_MSG(RES(), "Unsupported format in PVR texture: " + itos(flags & 0xFF) + "."); } w.release(); diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index 64f4c169cb..9b0a55eae3 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -57,8 +57,7 @@ void image_decompress_squish(Image *p_image) { } else if (p_image->get_format() == Image::FORMAT_RGTC_RG) { squish_flags = squish::kBc5; } else { - ERR_EXPLAIN("Squish: Can't decompress unknown format: " + itos(p_image->get_format())); - ERR_FAIL_COND(true); + ERR_FAIL_MSG("Squish: Can't decompress unknown format: " + itos(p_image->get_format()) + "."); return; } diff --git a/modules/svg/image_loader_svg.cpp b/modules/svg/image_loader_svg.cpp index b0cd648734..a2ef88d130 100644 --- a/modules/svg/image_loader_svg.cpp +++ b/modules/svg/image_loader_svg.cpp @@ -109,12 +109,10 @@ Error ImageLoaderSVG::_create_image(Ref<Image> p_image, const PoolVector<uint8_t float upscale = upsample ? 2.0 : 1.0; int w = (int)(svg_image->width * p_scale * upscale); - ERR_EXPLAIN(vformat("Can't create image from SVG with scale %s, the resulting image size exceeds max width.", rtos(p_scale))); - ERR_FAIL_COND_V(w > Image::MAX_WIDTH, ERR_PARAMETER_RANGE_ERROR); + ERR_FAIL_COND_V_MSG(w > Image::MAX_WIDTH, ERR_PARAMETER_RANGE_ERROR, vformat("Can't create image from SVG with scale %s, the resulting image size exceeds max width.", rtos(p_scale))); int h = (int)(svg_image->height * p_scale * upscale); - ERR_EXPLAIN(vformat("Can't create image from SVG with scale %s, the resulting image size exceeds max height.", rtos(p_scale))); - ERR_FAIL_COND_V(h > Image::MAX_HEIGHT, ERR_PARAMETER_RANGE_ERROR); + ERR_FAIL_COND_V_MSG(h > Image::MAX_HEIGHT, ERR_PARAMETER_RANGE_ERROR, vformat("Can't create image from SVG with scale %s, the resulting image size exceeds max height.", rtos(p_scale))); PoolVector<uint8_t> dst_image; dst_image.resize(w * h * 4); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 4425565afa..3f8b2b1831 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -328,8 +328,7 @@ void VisualScript::add_node(const StringName &p_func, int p_id, const Ref<Visual if (Object::cast_to<VisualScriptFunction>(*p_node)) { //the function indeed - ERR_EXPLAIN("A function node already has been set here."); - ERR_FAIL_COND(func.function_id >= 0); + ERR_FAIL_COND_MSG(func.function_id >= 0, "A function node has already been set here."); func.function_id = p_id; } @@ -1917,8 +1916,7 @@ Variant VisualScriptInstance::call(const StringName &p_method, const Variant **p if (!E) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; - ERR_EXPLAIN("No VisualScriptFunction node in function!"); - ERR_FAIL_V(Variant()); + ERR_FAIL_V_MSG(Variant(), "No VisualScriptFunction node in function."); } VisualScriptNodeInstance *node = E->get(); @@ -1974,8 +1972,7 @@ String VisualScriptInstance::to_string(bool *r_valid) { if (ret.get_type() != Variant::STRING) { if (r_valid) *r_valid = false; - ERR_EXPLAIN("Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); - ERR_FAIL_V(String()); + ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); } if (r_valid) *r_valid = true; @@ -2262,15 +2259,10 @@ Variant VisualScriptFunctionState::_signal_callback(const Variant **p_args, int ERR_FAIL_COND_V(function == StringName(), Variant()); #ifdef DEBUG_ENABLED - if (instance_id && !ObjectDB::get_instance(instance_id)) { - ERR_EXPLAIN("Resumed after yield, but class instance is gone"); - ERR_FAIL_V(Variant()); - } - if (script_id && !ObjectDB::get_instance(script_id)) { - ERR_EXPLAIN("Resumed after yield, but script is gone"); - ERR_FAIL_V(Variant()); - } + ERR_FAIL_COND_V_MSG(instance_id && !ObjectDB::get_instance(instance_id), Variant(), "Resumed after yield, but class instance is gone."); + ERR_FAIL_COND_V_MSG(script_id && !ObjectDB::get_instance(script_id), Variant(), "Resumed after yield, but script is gone."); + #endif r_error.error = Variant::CallError::CALL_OK; @@ -2329,15 +2321,10 @@ Variant VisualScriptFunctionState::resume(Array p_args) { ERR_FAIL_COND_V(function == StringName(), Variant()); #ifdef DEBUG_ENABLED - if (instance_id && !ObjectDB::get_instance(instance_id)) { - ERR_EXPLAIN("Resumed after yield, but class instance is gone"); - ERR_FAIL_V(Variant()); - } - if (script_id && !ObjectDB::get_instance(script_id)) { - ERR_EXPLAIN("Resumed after yield, but script is gone"); - ERR_FAIL_V(Variant()); - } + ERR_FAIL_COND_V_MSG(instance_id && !ObjectDB::get_instance(instance_id), Variant(), "Resumed after yield, but class instance is gone."); + ERR_FAIL_COND_V_MSG(script_id && !ObjectDB::get_instance(script_id), Variant(), "Resumed after yield, but script is gone."); + #endif Variant::CallError r_error; diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp index 2f4a45f108..2f56e778b9 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp @@ -116,8 +116,7 @@ int AudioStreamPlaybackOGGVorbis::mix(int16_t *p_buffer, int p_frames) { if (ret < 0) { playing = false; - ERR_EXPLAIN("Error reading OGG Vorbis File: " + file); - ERR_BREAK(ret < 0); + ERR_BREAK_MSG(ret < 0, "Error reading OGG Vorbis file: " + file + "."); } else if (ret == 0) { // end of song, reload? ov_clear(&vf); diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp index 3670edc9ea..fa3602ad27 100644 --- a/modules/webm/video_stream_webm.cpp +++ b/modules/webm/video_stream_webm.cpp @@ -53,8 +53,7 @@ public: file = FileAccess::open(p_file, FileAccess::READ); - ERR_EXPLAIN("Failed loading resource: '" + p_file + "';"); - ERR_FAIL_COND(!file); + ERR_FAIL_COND_MSG(!file, "Failed loading resource: '" + p_file + "'."); } ~MkvReader() { diff --git a/modules/webp/image_loader_webp.cpp b/modules/webp/image_loader_webp.cpp index 630c15f140..8986e49cf0 100644 --- a/modules/webp/image_loader_webp.cpp +++ b/modules/webp/image_loader_webp.cpp @@ -84,8 +84,7 @@ static Ref<Image> _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) { ERR_FAIL_COND_V(r[0] != 'W' || r[1] != 'E' || r[2] != 'B' || r[3] != 'P', Ref<Image>()); WebPBitstreamFeatures features; if (WebPGetFeatures(&r[4], size, &features) != VP8_STATUS_OK) { - ERR_EXPLAIN("Error unpacking WEBP image:"); - ERR_FAIL_V(Ref<Image>()); + ERR_FAIL_V_MSG(Ref<Image>(), "Error unpacking WEBP image."); } /* diff --git a/modules/webrtc/webrtc_data_channel_js.cpp b/modules/webrtc/webrtc_data_channel_js.cpp index 069918cc9c..996db35cba 100644 --- a/modules/webrtc/webrtc_data_channel_js.cpp +++ b/modules/webrtc/webrtc_data_channel_js.cpp @@ -68,10 +68,8 @@ void WebRTCDataChannelJS::_on_error() { } void WebRTCDataChannelJS::_on_message(uint8_t *p_data, uint32_t p_size, bool p_is_string) { - if (in_buffer.space_left() < (int)(p_size + 5)) { - ERR_EXPLAIN("Buffer full! Dropping data"); - ERR_FAIL(); - } + + ERR_FAIL_COND_MSG(in_buffer.space_left() < (int)(p_size + 5), "Buffer full! Dropping data."); uint8_t is_string = p_is_string ? 1 : 0; in_buffer.write((uint8_t *)&p_size, 4); diff --git a/modules/webrtc/webrtc_multiplayer.cpp b/modules/webrtc/webrtc_multiplayer.cpp index 17dafff93a..a759b17b83 100644 --- a/modules/webrtc/webrtc_multiplayer.cpp +++ b/modules/webrtc/webrtc_multiplayer.cpp @@ -321,10 +321,8 @@ Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size) if (target_peer > 0) { E = peer_map.find(target_peer); - if (!E) { - ERR_EXPLAIN("Invalid Target Peer: " + itos(target_peer)); - ERR_FAIL_V(ERR_INVALID_PARAMETER); - } + ERR_FAIL_COND_V_MSG(!E, ERR_INVALID_PARAMETER, "Invalid target peer: " + itos(target_peer) + "."); + ERR_FAIL_COND_V(E->value()->channels.size() <= ch, ERR_BUG); ERR_FAIL_COND_V(!E->value()->channels[ch].is_valid(), ERR_BUG); return E->value()->channels[ch]->put_packet(p_buffer, p_buffer_size); diff --git a/modules/webrtc/webrtc_peer_connection_gdnative.cpp b/modules/webrtc/webrtc_peer_connection_gdnative.cpp index af98aa750a..5e9dcb5366 100644 --- a/modules/webrtc/webrtc_peer_connection_gdnative.cpp +++ b/modules/webrtc/webrtc_peer_connection_gdnative.cpp @@ -51,13 +51,11 @@ Error WebRTCPeerConnectionGDNative::set_default_library(const godot_net_webrtc_l WebRTCPeerConnection *WebRTCPeerConnectionGDNative::_create() { WebRTCPeerConnectionGDNative *obj = memnew(WebRTCPeerConnectionGDNative); - ERR_EXPLAIN("Default GDNative WebRTC implementation not defined."); - ERR_FAIL_COND_V(!default_library, obj); + ERR_FAIL_COND_V_MSG(!default_library, obj, "Default GDNative WebRTC implementation not defined."); // Call GDNative constructor Error err = (Error)default_library->create_peer_connection(obj); - ERR_EXPLAIN("GDNative default library constructor returned an error"); - ERR_FAIL_COND_V(err != OK, obj); + ERR_FAIL_COND_V_MSG(err != OK, obj, "GDNative default library constructor returned an error."); return obj; } diff --git a/modules/websocket/emws_peer.cpp b/modules/websocket/emws_peer.cpp index a9f38f1a82..58d4c52688 100644 --- a/modules/websocket/emws_peer.cpp +++ b/modules/websocket/emws_peer.cpp @@ -131,14 +131,12 @@ void EMWSPeer::close(int p_code, String p_reason) { IP_Address EMWSPeer::get_connected_host() const { - ERR_EXPLAIN("Not supported in HTML5 export"); - ERR_FAIL_V(IP_Address()); + ERR_FAIL_V_MSG(IP_Address(), "Not supported in HTML5 export."); }; uint16_t EMWSPeer::get_connected_port() const { - ERR_EXPLAIN("Not supported in HTML5 export"); - ERR_FAIL_V(0); + ERR_FAIL_V_MSG(0, "Not supported in HTML5 export."); }; EMWSPeer::EMWSPeer() { diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp index e24cb850ec..62f09bfbf9 100644 --- a/modules/websocket/websocket_multiplayer_peer.cpp +++ b/modules/websocket/websocket_multiplayer_peer.cpp @@ -98,16 +98,14 @@ void WebSocketMultiplayerPeer::_bind_methods() { // int WebSocketMultiplayerPeer::get_available_packet_count() const { - ERR_EXPLAIN("Please use get_peer(ID).get_available_packet_count to get available packet count from peers when not using the MultiplayerAPI."); - ERR_FAIL_COND_V(!_is_multiplayer, ERR_UNCONFIGURED); + ERR_FAIL_COND_V_MSG(!_is_multiplayer, ERR_UNCONFIGURED, "Please use get_peer(ID).get_available_packet_count to get available packet count from peers when not using the MultiplayerAPI."); return _incoming_packets.size(); } Error WebSocketMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - ERR_EXPLAIN("Please use get_peer(ID).get_packet/var to communicate with peers when not using the MultiplayerAPI."); - ERR_FAIL_COND_V(!_is_multiplayer, ERR_UNCONFIGURED); + ERR_FAIL_COND_V_MSG(!_is_multiplayer, ERR_UNCONFIGURED, "Please use get_peer(ID).get_packet/var to communicate with peers when not using the MultiplayerAPI."); r_buffer_size = 0; @@ -127,8 +125,7 @@ Error WebSocketMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buff Error WebSocketMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - ERR_EXPLAIN("Please use get_peer(ID).put_packet/var to communicate with peers when not using the MultiplayerAPI."); - ERR_FAIL_COND_V(!_is_multiplayer, ERR_UNCONFIGURED); + ERR_FAIL_COND_V_MSG(!_is_multiplayer, ERR_UNCONFIGURED, "Please use get_peer(ID).put_packet/var to communicate with peers when not using the MultiplayerAPI."); PoolVector<uint8_t> buffer = _make_pkt(SYS_NONE, get_unique_id(), _target_peer, p_buffer, p_buffer_size); @@ -160,8 +157,7 @@ void WebSocketMultiplayerPeer::set_target_peer(int p_target_peer) { int WebSocketMultiplayerPeer::get_packet_peer() const { - ERR_EXPLAIN("This function is not available when not using the MultiplayerAPI."); - ERR_FAIL_COND_V(!_is_multiplayer, 1); + ERR_FAIL_COND_V_MSG(!_is_multiplayer, 1, "This function is not available when not using the MultiplayerAPI."); ERR_FAIL_COND_V(_incoming_packets.size() == 0, 1); return _incoming_packets.front()->get().source; @@ -354,8 +350,7 @@ void WebSocketMultiplayerPeer::_process_multiplayer(Ref<WebSocketPeer> p_peer, u _peer_id = id; break; default: - ERR_EXPLAIN("Invalid multiplayer message"); - ERR_FAIL(); + ERR_FAIL_MSG("Invalid multiplayer message."); break; } } diff --git a/modules/websocket/wsl_client.cpp b/modules/websocket/wsl_client.cpp index af75f2a320..cf2ad55b4a 100644 --- a/modules/websocket/wsl_client.cpp +++ b/modules/websocket/wsl_client.cpp @@ -53,8 +53,7 @@ void WSLClient::_do_handshake() { // Header is too big disconnect_from_host(); _on_error(); - ERR_EXPLAIN("Response headers too big"); - ERR_FAIL(); + ERR_FAIL_MSG("Response headers too big."); } Error err = _connection->get_partial_data(&_resp_buf[_resp_pos], 1, read); if (err == ERR_FILE_EOF) { @@ -81,8 +80,7 @@ void WSLClient::_do_handshake() { if (!_verify_headers(protocol)) { disconnect_from_host(); _on_error(); - ERR_EXPLAIN("Invalid response headers"); - ERR_FAIL(); + ERR_FAIL_MSG("Invalid response headers."); } // Create peer. WSLPeer::PeerData *data = memnew(struct WSLPeer::PeerData); @@ -103,29 +101,18 @@ bool WSLClient::_verify_headers(String &r_protocol) { String s = (char *)_resp_buf; Vector<String> psa = s.split("\r\n"); int len = psa.size(); - if (len < 4) { - ERR_EXPLAIN("Not enough response headers."); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(len < 4, false, "Not enough response headers, got: " + itos(len) + ", expected >= 4."); Vector<String> req = psa[0].split(" ", false); - if (req.size() < 2) { - ERR_EXPLAIN("Invalid protocol or status code."); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(req.size() < 2, false, "Invalid protocol or status code."); + // Wrong protocol - if (req[0] != "HTTP/1.1" || req[1] != "101") { - ERR_EXPLAIN("Invalid protocol or status code."); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(req[0] != "HTTP/1.1" || req[1] != "101", false, "Invalid protocol or status code."); Map<String, String> headers; for (int i = 1; i < len; i++) { Vector<String> header = psa[i].split(":", false, 1); - if (header.size() != 2) { - ERR_EXPLAIN("Invalid header -> " + psa[i]); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(header.size() != 2, false, "Invalid header -> " + psa[i] + "."); String name = header[0].to_lower(); String value = header[1].strip_edges(); if (headers.has(name)) @@ -251,8 +238,7 @@ void WSLClient::poll() { if (_connection == _tcp) { // Start SSL handshake ssl = Ref<StreamPeerSSL>(StreamPeerSSL::create()); - ERR_EXPLAIN("SSL is not available in this build"); - ERR_FAIL_COND(ssl.is_null()); + ERR_FAIL_COND_MSG(ssl.is_null(), "SSL is not available in this build."); ssl->set_blocking_handshake_enabled(false); if (ssl->connect_to_stream(_tcp, verify_ssl, _host) != OK) { disconnect_from_host(); @@ -332,8 +318,7 @@ uint16_t WSLClient::get_connected_port() const { } Error WSLClient::set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets) { - ERR_EXPLAIN("Buffers sizes can only be set before listening or connecting"); - ERR_FAIL_COND_V(_connection.is_valid(), FAILED); + ERR_FAIL_COND_V_MSG(_connection.is_valid(), FAILED, "Buffers sizes can only be set before listening or connecting."); _in_buf_size = nearest_shift(p_in_buffer - 1) + 10; _in_pkt_size = nearest_shift(p_in_packets - 1); diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp index 0d09a4d74e..1feae420b9 100644 --- a/modules/websocket/wsl_server.cpp +++ b/modules/websocket/wsl_server.cpp @@ -45,29 +45,18 @@ WSLServer::PendingPeer::PendingPeer() { bool WSLServer::PendingPeer::_parse_request(const PoolStringArray p_protocols) { Vector<String> psa = String((char *)req_buf).split("\r\n"); int len = psa.size(); - if (len < 4) { - ERR_EXPLAIN("Not enough response headers."); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(len < 4, false, "Not enough response headers, got: " + itos(len) + ", expected >= 4."); Vector<String> req = psa[0].split(" ", false); - if (req.size() < 2) { - ERR_EXPLAIN("Invalid protocol or status code."); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(req.size() < 2, false, "Invalid protocol or status code."); + // Wrong protocol - if (req[0] != "GET" || req[2] != "HTTP/1.1") { - ERR_EXPLAIN("Invalid method or HTTP version."); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(req[0] != "GET" || req[2] != "HTTP/1.1", false, "Invalid method or HTTP version."); Map<String, String> headers; for (int i = 1; i < len; i++) { Vector<String> header = psa[i].split(":", false, 1); - if (header.size() != 2) { - ERR_EXPLAIN("Invalid header -> " + psa[i]); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(header.size() != 2, false, "Invalid header -> " + psa[i]); String name = header[0].to_lower(); String value = header[1].strip_edges(); if (headers.has(name)) @@ -115,11 +104,7 @@ Error WSLServer::PendingPeer::do_handshake(PoolStringArray p_protocols) { if (!has_request) { int read = 0; while (true) { - if (req_pos >= WSL_MAX_HEADER_SIZE) { - // Header is too big - ERR_EXPLAIN("Response headers too big"); - ERR_FAIL_V(ERR_OUT_OF_MEMORY); - } + ERR_FAIL_COND_V_MSG(req_pos >= WSL_MAX_HEADER_SIZE, ERR_OUT_OF_MEMORY, "Response headers too big."); Error err = connection->get_partial_data(&req_buf[req_pos], 1, read); if (err != OK) // Got an error return FAILED; @@ -277,8 +262,7 @@ void WSLServer::disconnect_peer(int p_peer_id, int p_code, String p_reason) { } Error WSLServer::set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets) { - ERR_EXPLAIN("Buffers sizes can only be set before listening or connecting"); - ERR_FAIL_COND_V(_server->is_listening(), FAILED); + ERR_FAIL_COND_V_MSG(_server->is_listening(), FAILED, "Buffers sizes can only be set before listening or connecting."); _in_buf_size = nearest_shift(p_in_buffer - 1) + 10; _in_pkt_size = nearest_shift(p_in_packets - 1); diff --git a/platform/android/audio_driver_opensl.cpp b/platform/android/audio_driver_opensl.cpp index 3f7fd07997..711088c158 100644 --- a/platform/android/audio_driver_opensl.cpp +++ b/platform/android/audio_driver_opensl.cpp @@ -97,17 +97,10 @@ Error AudioDriverOpenSL::init() { { (SLuint32)SL_ENGINEOPTION_THREADSAFE, (SLuint32)SL_BOOLEAN_TRUE } }; res = slCreateEngine(&sl, 1, EngineOption, 0, NULL, NULL); - if (res != SL_RESULT_SUCCESS) { + ERR_FAIL_COND_V_MSG(res != SL_RESULT_SUCCESS, ERR_INVALID_PARAMETER, "Could not initialize OpenSL."); - ERR_EXPLAIN("Could not Initialize OpenSL"); - ERR_FAIL_V(ERR_INVALID_PARAMETER); - } res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - if (res != SL_RESULT_SUCCESS) { - - ERR_EXPLAIN("Could not Realize OpenSL"); - ERR_FAIL_V(ERR_INVALID_PARAMETER); - } + ERR_FAIL_COND_V_MSG(res != SL_RESULT_SUCCESS, ERR_INVALID_PARAMETER, "Could not realize OpenSL."); return OK; } diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 2fba8bbf7f..16e49e8a38 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -32,6 +32,7 @@ #include "core/io/marshalls.h" #include "core/io/zip_io.h" +#include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/os/os.h" #include "core/project_settings.h" @@ -725,8 +726,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { uint32_t string_at = decode_uint32(&p_manifest[st_offset + i * 4]); string_at += st_offset + string_count * 4; - ERR_EXPLAIN("Unimplemented, can't read utf8 string table."); - ERR_FAIL_COND(string_flags & UTF8_FLAG); + ERR_FAIL_COND_MSG(string_flags & UTF8_FLAG, "Unimplemented, can't read UTF-8 string table."); if (string_flags & UTF8_FLAG) { @@ -863,8 +863,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { memcpy(manifest_end.ptrw(), &p_manifest[ofs], manifest_end.size()); int32_t attr_name_string = string_table.find("name"); - ERR_EXPLAIN("Template does not have 'name' attribute"); - ERR_FAIL_COND(attr_name_string == -1); + ERR_FAIL_COND_MSG(attr_name_string == -1, "Template does not have 'name' attribute."); int32_t ns_android_string = string_table.find("http://schemas.android.com/apk/res/android"); if (ns_android_string == -1) { @@ -896,8 +895,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { } else if (dof_index == 2) { required_value_string = "true"; } else { - ERR_EXPLAIN("Unknown dof index " + itos(dof_index)); - ERR_FAIL(); + ERR_FAIL_MSG("Unknown DoF index: " + itos(dof_index) + "."); } int32_t required_value = string_table.find(required_value_string); if (required_value == -1) { @@ -989,12 +987,10 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { memcpy(manifest_end.ptrw(), &p_manifest[ofs], manifest_end.size()); int32_t attr_name_string = string_table.find("name"); - ERR_EXPLAIN("Template does not have 'name' attribute"); - ERR_FAIL_COND(attr_name_string == -1); + ERR_FAIL_COND_MSG(attr_name_string == -1, "Template does not have 'name' attribute."); int32_t ns_android_string = string_table.find("android"); - ERR_EXPLAIN("Template does not have 'android' namespace"); - ERR_FAIL_COND(ns_android_string == -1); + ERR_FAIL_COND_MSG(ns_android_string == -1, "Template does not have 'android' namespace."); int32_t attr_uses_permission_string = string_table.find("uses-permission"); if (attr_uses_permission_string == -1) { @@ -1403,8 +1399,9 @@ public: return ERR_UNCONFIGURED; } - //export_temp + // Export_temp APK. if (ep.step("Exporting APK", 0)) { + device_lock->unlock(); return ERR_SKIP; } @@ -1414,11 +1411,20 @@ public: if (use_reverse) p_debug_flags |= DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST; - String export_to = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport.apk"); - Error err = export_project(p_preset, true, export_to, p_debug_flags); - if (err) { - device_lock->unlock(); - return err; + String tmp_export_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport.apk"); + +#define CLEANUP_AND_RETURN(m_err) \ + { \ + DirAccess::remove_file_or_error(tmp_export_path); \ + device_lock->unlock(); \ + return m_err; \ + } + + // Export to temporary APK before sending to device. + Error err = export_project(p_preset, true, tmp_export_path, p_debug_flags); + + if (err != OK) { + CLEANUP_AND_RETURN(err); } List<String> args; @@ -1430,7 +1436,7 @@ public: if (remove_prev) { if (ep.step("Uninstalling...", 1)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } print_line("Uninstalling previous version: " + devices[p_device].name); @@ -1445,7 +1451,7 @@ public: print_line("Installing to device (please wait...): " + devices[p_device].name); if (ep.step("Installing to device (please wait...)", 2)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } args.clear(); @@ -1453,13 +1459,12 @@ public: args.push_back(devices[p_device].id); args.push_back("install"); args.push_back("-r"); - args.push_back(export_to); + args.push_back(tmp_export_path); err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv); if (err || rv != 0) { EditorNode::add_io_error("Could not install to device."); - device_lock->unlock(); - return ERR_CANT_CREATE; + CLEANUP_AND_RETURN(ERR_CANT_CREATE); } if (use_remote) { @@ -1513,7 +1518,7 @@ public: } if (ep.step("Running on Device...", 3)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } args.clear(); args.push_back("-s"); @@ -1533,11 +1538,11 @@ public: err = OS::get_singleton()->execute(adb, args, true, NULL, NULL, &rv); if (err || rv != 0) { EditorNode::add_io_error("Could not execute on device."); - device_lock->unlock(); - return ERR_CANT_CREATE; + CLEANUP_AND_RETURN(ERR_CANT_CREATE); } - device_lock->unlock(); - return OK; + + CLEANUP_AND_RETURN(OK); +#undef CLEANUP_AND_RETURN } virtual Ref<Texture> get_run_icon() const { @@ -2028,8 +2033,16 @@ public: zlib_filefunc_def io2 = io; FileAccess *dst_f = NULL; io2.opaque = &dst_f; - String unaligned_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport-unaligned.apk"); - zipFile unaligned_apk = zipOpen2(unaligned_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2); + + String tmp_unaligned_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport-unaligned.apk"); + +#define CLEANUP_AND_RETURN(m_err) \ + { \ + DirAccess::remove_file_or_error(tmp_unaligned_path); \ + return m_err; \ + } + + zipFile unaligned_apk = zipOpen2(tmp_unaligned_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io2); bool use_32_fb = p_preset->get("graphics/32_bits_framebuffer"); bool immersive = p_preset->get("screen/immersive_mode"); @@ -2157,7 +2170,7 @@ public: } if (ep.step("Adding Files...", 1)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } Error err = OK; Vector<String> cl = cmdline.strip_edges().split(" "); @@ -2189,7 +2202,7 @@ public: unzClose(pkg); EditorNode::add_io_error("Could not write expansion package file: " + apkfname); - return OK; + CLEANUP_AND_RETURN(ERR_SKIP); } cl.push_back("--use_apk_expansion"); @@ -2276,8 +2289,8 @@ public: zipClose(unaligned_apk, NULL); unzClose(pkg); - if (err) { - return err; + if (err != OK) { + CLEANUP_AND_RETURN(err); } if (_signed) { @@ -2285,7 +2298,7 @@ public: String jarsigner = EditorSettings::get_singleton()->get("export/android/jarsigner"); if (!FileAccess::exists(jarsigner)) { EditorNode::add_io_error("'jarsigner' could not be found.\nPlease supply a path in the Editor Settings.\nThe resulting APK is unsigned."); - return OK; + CLEANUP_AND_RETURN(OK); } String keystore; @@ -2305,7 +2318,7 @@ public: } if (ep.step("Signing debug APK...", 103)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } } else { @@ -2314,13 +2327,13 @@ public: user = release_username; if (ep.step("Signing release APK...", 103)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } } if (!FileAccess::exists(keystore)) { EditorNode::add_io_error("Could not find keystore, unable to export."); - return ERR_FILE_CANT_OPEN; + CLEANUP_AND_RETURN(ERR_FILE_CANT_OPEN); } List<String> args; @@ -2338,30 +2351,30 @@ public: args.push_back(keystore); args.push_back("-storepass"); args.push_back(password); - args.push_back(unaligned_path); + args.push_back(tmp_unaligned_path); args.push_back(user); int retval; OS::get_singleton()->execute(jarsigner, args, true, NULL, NULL, &retval); if (retval) { EditorNode::add_io_error("'jarsigner' returned with error #" + itos(retval)); - return ERR_CANT_CREATE; + CLEANUP_AND_RETURN(ERR_CANT_CREATE); } if (ep.step("Verifying APK...", 104)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } args.clear(); args.push_back("-verify"); args.push_back("-keystore"); args.push_back(keystore); - args.push_back(unaligned_path); + args.push_back(tmp_unaligned_path); args.push_back("-verbose"); OS::get_singleton()->execute(jarsigner, args, true, NULL, NULL, &retval); if (retval) { EditorNode::add_io_error("'jarsigner' verification of APK failed. Make sure to use a jarsigner from OpenJDK 8."); - return ERR_CANT_CREATE; + CLEANUP_AND_RETURN(ERR_CANT_CREATE); } } @@ -2370,14 +2383,14 @@ public: static const int ZIP_ALIGNMENT = 4; if (ep.step("Aligning APK...", 105)) { - return ERR_SKIP; + CLEANUP_AND_RETURN(ERR_SKIP); } - unzFile tmp_unaligned = unzOpen2(unaligned_path.utf8().get_data(), &io); + unzFile tmp_unaligned = unzOpen2(tmp_unaligned_path.utf8().get_data(), &io); if (!tmp_unaligned) { - EditorNode::add_io_error("Could not find temp unaligned APK."); - return ERR_FILE_NOT_FOUND; + EditorNode::add_io_error("Could not unzip temporary unaligned APK."); + CLEANUP_AND_RETURN(ERR_FILE_NOT_FOUND); } ret = unzGoToFirstFile(tmp_unaligned); @@ -2447,7 +2460,7 @@ public: zipClose(final_apk, NULL); unzClose(tmp_unaligned); - return OK; + CLEANUP_AND_RETURN(OK); } virtual void get_platform_features(List<String> *r_features) { diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp index 77f077456e..1159e93166 100644 --- a/platform/android/java_godot_lib_jni.cpp +++ b/platform/android/java_godot_lib_jni.cpp @@ -686,20 +686,11 @@ static void _initialize_java_modules() { print_line("Loading Android module: " + m); jstring strClassName = env->NewStringUTF(m.utf8().get_data()); jclass singletonClass = (jclass)env->CallObjectMethod(cls, findClass, strClassName); - - if (!singletonClass) { - - ERR_EXPLAIN("Couldn't find singleton for class: " + m); - ERR_CONTINUE(!singletonClass); - } + ERR_CONTINUE_MSG(!singletonClass, "Couldn't find singleton for class: " + m + "."); jmethodID initialize = env->GetStaticMethodID(singletonClass, "initialize", "(Landroid/app/Activity;)Lorg/godotengine/godot/Godot$SingletonBase;"); + ERR_CONTINUE_MSG(!initialize, "Couldn't find proper initialize function 'public static Godot.SingletonBase Class::initialize(Activity p_activity)' initializer for singleton class: " + m + "."); - if (!initialize) { - - ERR_EXPLAIN("Couldn't find proper initialize function 'public static Godot.SingletonBase Class::initialize(Activity p_activity)' initializer for singleton class: " + m); - ERR_CONTINUE(!initialize); - } jobject obj = env->CallStaticObjectMethod(singletonClass, initialize, godot_java->get_activity()); env->NewGlobalRef(obj); } diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index ebc319e57d..701a351203 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -71,8 +71,7 @@ const char *OS_Android::get_video_driver_name(int p_driver) const { case VIDEO_DRIVER_GLES2: return "GLES2"; } - ERR_EXPLAIN("Invalid video driver index " + itos(p_driver)); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Invalid video driver index: " + itos(p_driver) + "."); } int OS_Android::get_audio_driver_count() const { @@ -223,10 +222,7 @@ bool OS_Android::request_permission(const String &p_name) { Error OS_Android::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) { p_library_handle = dlopen(p_path.utf8().get_data(), RTLD_NOW); - if (!p_library_handle) { - ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + dlerror()); - ERR_FAIL_V(ERR_CANT_OPEN); - } + ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ", error: " + dlerror() + "."); return OK; } diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp index a179b36bd5..1cbf4d6a70 100644 --- a/platform/iphone/export/export.cpp +++ b/platform/iphone/export/export.cpp @@ -768,8 +768,7 @@ Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir DirAccess *da = DirAccess::create_for_path(asset); if (!da) { memdelete(filesystem_da); - ERR_EXPLAIN("Can't create directory: " + asset); - ERR_FAIL_V(ERR_CANT_CREATE); + ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't create directory: " + asset + "."); } bool file_exists = da->file_exists(asset); bool dir_exists = da->dir_exists(asset); @@ -848,8 +847,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p EditorProgress ep("export", "Exporting for iOS", 5, true); String team_id = p_preset->get("application/app_store_team_id"); - ERR_EXPLAIN("App Store Team ID not specified - cannot configure the project."); - ERR_FAIL_COND_V(team_id.length() == 0, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(team_id.length() == 0, ERR_CANT_OPEN, "App Store Team ID not specified - cannot configure the project."); if (p_debug) src_pkg_name = p_preset->get("custom_package/debug"); diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index f5fce66059..825342f911 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -64,8 +64,7 @@ const char *OSIPhone::get_video_driver_name(int p_driver) const { case VIDEO_DRIVER_GLES2: return "GLES2"; } - ERR_EXPLAIN("Invalid video driver index " + itos(p_driver)); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Invalid video driver index: " + itos(p_driver) + "."); }; OSIPhone *OSIPhone::get_singleton() { diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp index 163826f828..b359699d3a 100644 --- a/platform/javascript/audio_driver_javascript.cpp +++ b/platform/javascript/audio_driver_javascript.cpp @@ -63,7 +63,7 @@ void AudioDriverJavaScript::mix_to_js() { void AudioDriverJavaScript::process_capture(float sample) { int32_t sample32 = int32_t(sample * 32768.f) * (1U << 16); - input_buffer_write(sample32); + capture_buffer_write(sample32); } Error AudioDriverJavaScript::init() { @@ -198,7 +198,7 @@ void AudioDriverJavaScript::finish() { Error AudioDriverJavaScript::capture_start() { - input_buffer_init(buffer_length); + capture_buffer_init(buffer_length); /* clang-format off */ EM_ASM({ @@ -245,8 +245,6 @@ Error AudioDriverJavaScript::capture_stop() { }); /* clang-format on */ - input_buffer.clear(); - return OK; } diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index c68b420c61..69dd038709 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -362,12 +362,21 @@ int EditorExportPlatformJavaScript::get_device_count() const { Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) { - String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_export.html"); + String basepath = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_js_export"); + String path = basepath + ".html"; Error err = export_project(p_preset, true, path, p_debug_flags); - if (err) { + if (err != OK) { + // Export generates several files, clean them up on failure. + DirAccess::remove_file_or_error(basepath + ".html"); + DirAccess::remove_file_or_error(basepath + ".js"); + DirAccess::remove_file_or_error(basepath + ".pck"); + DirAccess::remove_file_or_error(basepath + ".png"); + DirAccess::remove_file_or_error(basepath + ".wasm"); return err; } OS::get_singleton()->shell_open(String("file://") + path); + // FIXME: Find out how to clean up export files after running the successfully + // exported game. Might not be trivial. return OK; } diff --git a/platform/javascript/http_client_javascript.cpp b/platform/javascript/http_client_javascript.cpp index b4bab9a999..e6e933811f 100644 --- a/platform/javascript/http_client_javascript.cpp +++ b/platform/javascript/http_client_javascript.cpp @@ -68,21 +68,18 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) { - ERR_EXPLAIN("Accessing an HTTPClient's StreamPeer is not supported for the HTML5 platform"); - ERR_FAIL(); + ERR_FAIL_MSG("Accessing an HTTPClient's StreamPeer is not supported for the HTML5 platform."); } Ref<StreamPeer> HTTPClient::get_connection() const { - ERR_EXPLAIN("Accessing an HTTPClient's StreamPeer is not supported for the HTML5 platform"); - ERR_FAIL_V(REF()); + ERR_FAIL_V_MSG(REF(), "Accessing an HTTPClient's StreamPeer is not supported for the HTML5 platform."); } Error HTTPClient::prepare_request(Method p_method, const String &p_url, const Vector<String> &p_headers) { ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER); - ERR_EXPLAIN("HTTP methods TRACE and CONNECT are not supported for the HTML5 platform"); - ERR_FAIL_COND_V(p_method == METHOD_TRACE || p_method == METHOD_CONNECT, ERR_UNAVAILABLE); + ERR_FAIL_COND_V_MSG(p_method == METHOD_TRACE || p_method == METHOD_CONNECT, ERR_UNAVAILABLE, "HTTP methods TRACE and CONNECT are not supported for the HTML5 platform."); ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(host.empty(), ERR_UNCONFIGURED); ERR_FAIL_COND_V(port < 0, ERR_UNCONFIGURED); @@ -201,8 +198,7 @@ PoolByteArray HTTPClient::read_response_body_chunk() { void HTTPClient::set_blocking_mode(bool p_enable) { - ERR_EXPLAIN("HTTPClient blocking mode is not supported for the HTML5 platform"); - ERR_FAIL_COND(p_enable); + ERR_FAIL_COND_MSG(p_enable, "HTTPClient blocking mode is not supported for the HTML5 platform."); } bool HTTPClient::is_blocking_mode_enabled() const { diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 5363cd4af7..0179bf813d 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -192,9 +192,8 @@ void OS_JavaScript::set_window_fullscreen(bool p_enabled) { strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT; strategy.canvasResizedCallback = NULL; EMSCRIPTEN_RESULT result = emscripten_request_fullscreen_strategy(NULL, false, &strategy); - ERR_EXPLAIN("Enabling fullscreen is only possible from an input callback for the HTML5 platform"); - ERR_FAIL_COND(result == EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED); - ERR_FAIL_COND(result != EMSCRIPTEN_RESULT_SUCCESS); + ERR_FAIL_COND_MSG(result == EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED, "Enabling fullscreen is only possible from an input callback for the HTML5 platform."); + ERR_FAIL_COND_MSG(result != EMSCRIPTEN_RESULT_SUCCESS, "Enabling fullscreen is only possible from an input callback for the HTML5 platform."); // Not fullscreen yet, so prevent "windowed" canvas dimensions from // being overwritten. entering_fullscreen = true; @@ -582,8 +581,7 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s void OS_JavaScript::set_mouse_mode(OS::MouseMode p_mode) { - ERR_EXPLAIN("MOUSE_MODE_CONFINED is not supported for the HTML5 platform"); - ERR_FAIL_COND(p_mode == MOUSE_MODE_CONFINED); + ERR_FAIL_COND_MSG(p_mode == MOUSE_MODE_CONFINED, "MOUSE_MODE_CONFINED is not supported for the HTML5 platform."); if (p_mode == get_mouse_mode()) return; @@ -602,9 +600,8 @@ void OS_JavaScript::set_mouse_mode(OS::MouseMode p_mode) { } else if (p_mode == MOUSE_MODE_CAPTURED) { EMSCRIPTEN_RESULT result = emscripten_request_pointerlock("canvas", false); - ERR_EXPLAIN("MOUSE_MODE_CAPTURED can only be entered from within an appropriate input callback"); - ERR_FAIL_COND(result == EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED); - ERR_FAIL_COND(result != EMSCRIPTEN_RESULT_SUCCESS); + ERR_FAIL_COND_MSG(result == EMSCRIPTEN_RESULT_FAILED_NOT_DEFERRED, "MOUSE_MODE_CAPTURED can only be entered from within an appropriate input callback."); + ERR_FAIL_COND_MSG(result != EMSCRIPTEN_RESULT_SUCCESS, "MOUSE_MODE_CAPTURED can only be entered from within an appropriate input callback."); // set_css_cursor must be called before set_cursor_shape to make the cursor visible set_css_cursor(godot2dom_cursor(cursor_shape)); set_cursor_shape(cursor_shape); @@ -810,8 +807,7 @@ const char *OS_JavaScript::get_video_driver_name(int p_driver) const { case VIDEO_DRIVER_GLES2: return "GLES2"; } - ERR_EXPLAIN("Invalid video driver index " + itos(p_driver)); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Invalid video driver index: " + itos(p_driver) + "."); } // Audio @@ -846,8 +842,7 @@ void OS_JavaScript::set_clipboard(const String &p_text) { return 0; }, p_text.utf8().get_data()); /* clang-format on */ - ERR_EXPLAIN("Clipboard API is not supported."); - ERR_FAIL_COND(err); + ERR_FAIL_COND_MSG(err, "Clipboard API is not supported."); } String OS_JavaScript::get_clipboard() const { @@ -1117,20 +1112,17 @@ void OS_JavaScript::finalize() { Error OS_JavaScript::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex) { - ERR_EXPLAIN("OS::execute() is not available on the HTML5 platform"); - ERR_FAIL_V(ERR_UNAVAILABLE); + ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "OS::execute() is not available on the HTML5 platform."); } Error OS_JavaScript::kill(const ProcessID &p_pid) { - ERR_EXPLAIN("OS::kill() is not available on the HTML5 platform"); - ERR_FAIL_V(ERR_UNAVAILABLE); + ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "OS::kill() is not available on the HTML5 platform."); } int OS_JavaScript::get_process_id() const { - ERR_EXPLAIN("OS::get_process_id() is not available on the HTML5 platform"); - ERR_FAIL_V(0); + ERR_FAIL_V_MSG(0, "OS::get_process_id() is not available on the HTML5 platform."); } extern "C" EMSCRIPTEN_KEEPALIVE void send_notification(int p_notification) { diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index 8cabc45250..56b0a44dbc 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -29,9 +29,11 @@ /*************************************************************************/ #include "export.h" + #include "core/io/marshalls.h" #include "core/io/resource_saver.h" #include "core/io/zip_io.h" +#include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/os/os.h" #include "core/project_settings.h" @@ -244,13 +246,17 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_ copy->resize(icon_infos[i].size, icon_infos[i].size); if (icon_infos[i].is_png) { - //encode png icon + // Encode PNG icon. it->create_from_image(copy); String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("icon.png"); ResourceSaver::save(path, it); FileAccess *f = FileAccess::open(path, FileAccess::READ); - ERR_FAIL_COND(!f); + if (!f) { + // Clean up generated file. + DirAccess::remove_file_or_error(path); + ERR_FAIL(); + } int ofs = data.size(); uint32_t len = f->get_len(); @@ -261,6 +267,10 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_ len = BSWAP32(len); copymem(&data.write[ofs], icon_infos[i].name, 4); encode_uint32(len, &data.write[ofs + 4]); + + // Clean up generated file. + DirAccess::remove_file_or_error(path); + } else { PoolVector<uint8_t> src_data = copy->get_data(); @@ -561,7 +571,6 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p } } } - //bleh? } if (data.size() > 0) { @@ -687,7 +696,8 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p // Clean up temporary .app dir OS::get_singleton()->move_to_trash(tmp_app_path_name); - } else { + + } else { // pck String pack_path = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".pck"); @@ -747,6 +757,9 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p zipCloseFileInZip(dst_pkg_zip); } } + + // Clean up generated file. + DirAccess::remove_file_or_error(pack_path); } } diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index a48f784529..ab77897b08 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1719,10 +1719,7 @@ Error OS_OSX::open_dynamic_library(const String p_path, void *&p_library_handle, } p_library_handle = dlopen(path.utf8().get_data(), RTLD_NOW); - if (!p_library_handle) { - ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + dlerror()); - ERR_FAIL_V(ERR_CANT_OPEN); - } + ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ", error: " + dlerror() + "."); return OK; } @@ -1962,15 +1959,10 @@ void OS_OSX::set_native_icon(const String &p_filename) { memdelete(f); NSData *icon_data = [[[NSData alloc] initWithBytes:&data.write[0] length:len] autorelease]; - if (!icon_data) { - ERR_EXPLAIN("Error reading icon data"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!icon_data, "Error reading icon data."); + NSImage *icon = [[[NSImage alloc] initWithData:icon_data] autorelease]; - if (!icon) { - ERR_EXPLAIN("Error loading icon"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!icon, "Error loading icon."); [NSApp setApplicationIconImage:icon]; } diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp index 75ce422e9e..662ee49935 100644 --- a/platform/uwp/export/export.cpp +++ b/platform/uwp/export/export.cpp @@ -34,6 +34,7 @@ #include "core/io/zip_io.h" #include "core/math/crypto_core.h" #include "core/object.h" +#include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/project_settings.h" #include "core/version.h" @@ -133,8 +134,6 @@ class AppxPackager { String progress_task; FileAccess *package; - String tmp_blockmap_file_path; - String tmp_content_types_file_path; Set<String> mime_types; @@ -146,8 +145,8 @@ class AppxPackager { String hash_block(const uint8_t *p_block_data, size_t p_block_len); - void make_block_map(); - void make_content_types(); + void make_block_map(const String &p_path); + void make_content_types(const String &p_path); _FORCE_INLINE_ unsigned int buf_put_int16(uint16_t p_val, uint8_t *p_buf) { for (int i = 0; i < 2; i++) { @@ -208,9 +207,9 @@ String AppxPackager::hash_block(const uint8_t *p_block_data, size_t p_block_len) return String(base64); } -void AppxPackager::make_block_map() { +void AppxPackager::make_block_map(const String &p_path) { - FileAccess *tmp_file = FileAccess::open(tmp_blockmap_file_path, FileAccess::WRITE); + FileAccess *tmp_file = FileAccess::open(p_path, FileAccess::WRITE); tmp_file->store_string("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); tmp_file->store_string("<BlockMap xmlns=\"http://schemas.microsoft.com/appx/2010/blockmap\" HashMethod=\"http://www.w3.org/2001/04/xmlenc#sha256\">"); @@ -253,9 +252,9 @@ String AppxPackager::content_type(String p_extension) { return "application/octet-stream"; } -void AppxPackager::make_content_types() { +void AppxPackager::make_content_types(const String &p_path) { - FileAccess *tmp_file = FileAccess::open(tmp_content_types_file_path, FileAccess::WRITE); + FileAccess *tmp_file = FileAccess::open(p_path, FileAccess::WRITE); tmp_file->store_string("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); tmp_file->store_string("<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">"); @@ -458,8 +457,6 @@ void AppxPackager::init(FileAccess *p_fa) { package = p_fa; central_dir_offset = 0; end_of_central_dir_offset = 0; - tmp_blockmap_file_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpblockmap.xml"); - tmp_content_types_file_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpcontenttypes.xml"); } Error AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress) { @@ -591,7 +588,9 @@ void AppxPackager::finish() { // Create and add block map file EditorNode::progress_task_step("export", "Creating block map...", 4); - make_block_map(); + const String &tmp_blockmap_file_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpblockmap.xml"); + make_block_map(tmp_blockmap_file_path); + FileAccess *blockmap_file = FileAccess::open(tmp_blockmap_file_path, FileAccess::READ); Vector<uint8_t> blockmap_buffer; blockmap_buffer.resize(blockmap_file->get_len()); @@ -604,8 +603,11 @@ void AppxPackager::finish() { memdelete(blockmap_file); // Add content types + EditorNode::progress_task_step("export", "Setting content types...", 5); - make_content_types(); + + const String &tmp_content_types_file_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpcontenttypes.xml"); + make_content_types(tmp_content_types_file_path); FileAccess *types_file = FileAccess::open(tmp_content_types_file_path, FileAccess::READ); Vector<uint8_t> types_buffer; @@ -618,6 +620,10 @@ void AppxPackager::finish() { types_file->close(); memdelete(types_file); + // Cleanup generated files. + DirAccess::remove_file_or_error(tmp_blockmap_file_path); + DirAccess::remove_file_or_error(tmp_content_types_file_path); + // Pre-process central directory before signing for (int i = 0; i < file_metadata.size(); i++) { store_central_dir_header(file_metadata[i]); @@ -901,8 +907,7 @@ class EditorExportPlatformUWP : public EditorExportPlatform { String err_string = "Couldn't save temp logo file."; EditorNode::add_io_error(err_string); - ERR_EXPLAIN(err_string); - ERR_FAIL_V(data); + ERR_FAIL_V_MSG(data, err_string); } FileAccess *f = FileAccess::open(tmp_path, FileAccess::READ, &err); @@ -910,10 +915,10 @@ class EditorExportPlatformUWP : public EditorExportPlatform { if (err != OK) { String err_string = "Couldn't open temp logo file."; - + // Cleanup generated file. + DirAccess::remove_file_or_error(tmp_path); EditorNode::add_io_error(err_string); - ERR_EXPLAIN(err_string); - ERR_FAIL_V(data); + ERR_FAIL_V_MSG(data, err_string); } data.resize(f->get_len()); @@ -921,31 +926,7 @@ class EditorExportPlatformUWP : public EditorExportPlatform { f->close(); memdelete(f); - - // Delete temp file - DirAccess *dir = DirAccess::open(tmp_path.get_base_dir(), &err); - - if (err != OK) { - - String err_string = "Couldn't open temp path to remove temp logo file."; - - EditorNode::add_io_error(err_string); - ERR_EXPLAIN(err_string); - ERR_FAIL_V(data); - } - - err = dir->remove(tmp_path); - - memdelete(dir); - - if (err != OK) { - - String err_string = "Couldn't remove temp logo file."; - - EditorNode::add_io_error(err_string); - ERR_EXPLAIN(err_string); - ERR_FAIL_V(data); - } + DirAccess::remove_file_or_error(tmp_path); return data; } diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 9d9be44ce5..60f2290355 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -835,11 +835,7 @@ Error OS_UWP::open_dynamic_library(const String p_path, void *&p_library_handle, String full_path = "game/" + p_path; p_library_handle = (void *)LoadPackagedLibrary(full_path.c_str(), 0); - - if (!p_library_handle) { - ERR_EXPLAIN("Can't open dynamic library: " + full_path + ". Error: " + format_error_message(GetLastError())); - ERR_FAIL_V(ERR_CANT_OPEN); - } + ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + full_path + ", error: " + format_error_message(GetLastError()) + "."); return OK; } @@ -854,8 +850,7 @@ Error OS_UWP::get_dynamic_library_symbol_handle(void *p_library_handle, const St p_symbol_handle = (void *)GetProcAddress((HMODULE)p_library_handle, p_name.utf8().get_data()); if (!p_symbol_handle) { if (!p_optional) { - ERR_EXPLAIN("Can't resolve symbol " + p_name + ". Error: " + String::num(GetLastError())); - ERR_FAIL_V(ERR_CANT_RESOLVE); + ERR_FAIL_V_MSG(ERR_CANT_RESOLVE, "Can't resolve symbol " + p_name + ", error: " + String::num(GetLastError()) + "."); } else { return ERR_CANT_RESOLVE; } diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index db4575a0cb..be325381bb 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1435,16 +1435,13 @@ void OS_Windows::set_clipboard(const String &p_text) { String text = p_text.replace("\n", "\r\n"); if (!OpenClipboard(hWnd)) { - ERR_EXPLAIN("Unable to open clipboard."); - ERR_FAIL(); - }; + ERR_FAIL_MSG("Unable to open clipboard."); + } EmptyClipboard(); HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (text.length() + 1) * sizeof(CharType)); - if (mem == NULL) { - ERR_EXPLAIN("Unable to allocate memory for clipboard contents."); - ERR_FAIL(); - }; + ERR_FAIL_COND_MSG(mem == NULL, "Unable to allocate memory for clipboard contents."); + LPWSTR lptstrCopy = (LPWSTR)GlobalLock(mem); memcpy(lptstrCopy, text.c_str(), (text.length() + 1) * sizeof(CharType)); GlobalUnlock(mem); @@ -1454,10 +1451,8 @@ void OS_Windows::set_clipboard(const String &p_text) { // set the CF_TEXT version (not needed?) CharString utf8 = text.utf8(); mem = GlobalAlloc(GMEM_MOVEABLE, utf8.length() + 1); - if (mem == NULL) { - ERR_EXPLAIN("Unable to allocate memory for clipboard contents."); - ERR_FAIL(); - }; + ERR_FAIL_COND_MSG(mem == NULL, "Unable to allocate memory for clipboard contents."); + LPTSTR ptr = (LPTSTR)GlobalLock(mem); memcpy(ptr, utf8.get_data(), utf8.length()); ptr[utf8.length()] = 0; @@ -1472,8 +1467,7 @@ String OS_Windows::get_clipboard() const { String ret; if (!OpenClipboard(hWnd)) { - ERR_EXPLAIN("Unable to open clipboard."); - ERR_FAIL_V(""); + ERR_FAIL_V_MSG("", "Unable to open clipboard."); }; if (IsClipboardFormatAvailable(CF_UNICODETEXT)) { @@ -2135,15 +2129,12 @@ Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_han } p_library_handle = (void *)LoadLibraryExW(path.c_str(), NULL, (p_also_set_library_path && has_dll_directory_api) ? LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0); + ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ", error: " + format_error_message(GetLastError()) + "."); if (cookie) { remove_dll_directory(cookie); } - if (!p_library_handle) { - ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + format_error_message(GetLastError())); - ERR_FAIL_V(ERR_CANT_OPEN); - } return OK; } @@ -2158,8 +2149,7 @@ Error OS_Windows::get_dynamic_library_symbol_handle(void *p_library_handle, cons p_symbol_handle = (void *)GetProcAddress((HMODULE)p_library_handle, p_name.utf8().get_data()); if (!p_symbol_handle) { if (!p_optional) { - ERR_EXPLAIN("Can't resolve symbol " + p_name + ". Error: " + String::num(GetLastError())); - ERR_FAIL_V(ERR_CANT_RESOLVE); + ERR_FAIL_V_MSG(ERR_CANT_RESOLVE, "Can't resolve symbol " + p_name + ", error: " + String::num(GetLastError()) + "."); } else { return ERR_CANT_RESOLVE; } @@ -2686,10 +2676,7 @@ void OS_Windows::set_native_icon(const String &p_filename) { pos += sizeof(WORD); f->seek(pos); - if (icon_dir->idType != 1) { - ERR_EXPLAIN("Invalid icon file format!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(icon_dir->idType != 1, "Invalid icon file format!"); icon_dir->idCount = f->get_32(); pos += sizeof(WORD); @@ -2722,10 +2709,7 @@ void OS_Windows::set_native_icon(const String &p_filename) { } } - if (big_icon_index == -1) { - ERR_EXPLAIN("No valid icons found!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(big_icon_index == -1, "No valid icons found!"); if (small_icon_index == -1) { WARN_PRINTS("No small icon found, reusing " + itos(big_icon_width) + "x" + itos(big_icon_width) + " @" + itos(big_icon_cc) + " icon!"); @@ -2741,10 +2725,7 @@ void OS_Windows::set_native_icon(const String &p_filename) { f->seek(pos); f->get_buffer((uint8_t *)&data_big.write[0], bytecount_big); HICON icon_big = CreateIconFromResource((PBYTE)&data_big.write[0], bytecount_big, TRUE, 0x00030000); - if (!icon_big) { - ERR_EXPLAIN("Could not create " + itos(big_icon_width) + "x" + itos(big_icon_width) + " @" + itos(big_icon_cc) + " icon, error: " + format_error_message(GetLastError())); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!icon_big, "Could not create " + itos(big_icon_width) + "x" + itos(big_icon_width) + " @" + itos(big_icon_cc) + " icon, error: " + format_error_message(GetLastError()) + "."); // Read the small icon DWORD bytecount_small = icon_dir->idEntries[small_icon_index].dwBytesInRes; @@ -2754,10 +2735,7 @@ void OS_Windows::set_native_icon(const String &p_filename) { f->seek(pos); f->get_buffer((uint8_t *)&data_small.write[0], bytecount_small); HICON icon_small = CreateIconFromResource((PBYTE)&data_small.write[0], bytecount_small, TRUE, 0x00030000); - if (!icon_small) { - ERR_EXPLAIN("Could not create 16x16 @" + itos(small_icon_cc) + " icon, error: " + format_error_message(GetLastError())); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!icon_small, "Could not create 16x16 @" + itos(small_icon_cc) + " icon, error: " + format_error_message(GetLastError()) + "."); // Online tradition says to be sure last error is cleared and set the small icon first int err = 0; @@ -2765,17 +2743,11 @@ void OS_Windows::set_native_icon(const String &p_filename) { SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)icon_small); err = GetLastError(); - if (err) { - ERR_EXPLAIN("Error setting ICON_SMALL: " + format_error_message(err)); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(err, "Error setting ICON_SMALL: " + format_error_message(err) + "."); SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)icon_big); err = GetLastError(); - if (err) { - ERR_EXPLAIN("Error setting ICON_BIG: " + format_error_message(err)); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(err, "Error setting ICON_BIG: " + format_error_message(err) + "."); memdelete(f); memdelete(icon_dir); diff --git a/platform/x11/export/export.cpp b/platform/x11/export/export.cpp index 8767aac517..6e66173463 100644 --- a/platform/x11/export/export.cpp +++ b/platform/x11/export/export.cpp @@ -85,8 +85,7 @@ static Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, if (bits == 32 && p_embedded_size >= 0x100000000) { f->close(); - ERR_EXPLAIN("32-bit executables cannot have embedded data >= 4 GiB"); - ERR_FAIL_V(ERR_INVALID_DATA); + ERR_FAIL_V_MSG(ERR_INVALID_DATA, "32-bit executables cannot have embedded data >= 4 GiB."); } // Get info about the section header table diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 0d1e702d04..ca72393e43 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -1518,9 +1518,12 @@ void OS_X11::set_window_maximized(bool p_enabled) { XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); - if (is_window_maximize_allowed()) { - while (p_enabled && !is_window_maximized()) { - // Wait for effective resizing (so the GLX context is too). + if (p_enabled && is_window_maximize_allowed()) { + // Wait for effective resizing (so the GLX context is too). + // Give up after 0.5s, it's not going to happen on this WM. + // https://github.com/godotengine/godot/issues/19978 + for (int attempt = 0; !is_window_maximized() && attempt < 50; attempt++) { + usleep(10000); } } diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp index 83cc1eeb46..0b20b781f0 100644 --- a/scene/2d/animated_sprite.cpp +++ b/scene/2d/animated_sprite.cpp @@ -642,9 +642,8 @@ void AnimatedSprite::_reset_timeout() { void AnimatedSprite::set_animation(const StringName &p_animation) { - ERR_EXPLAIN(vformat("There is no animation with name '%s'.", p_animation)); - ERR_FAIL_COND(frames == NULL); - ERR_FAIL_COND(frames->get_animation_names().find(p_animation) == -1); + ERR_FAIL_COND_MSG(frames == NULL, vformat("There is no animation with name '%s'.", p_animation)); + ERR_FAIL_COND_MSG(frames->get_animation_names().find(p_animation) == -1, vformat("There is no animation with name '%s'.", p_animation)); if (animation == p_animation) return; diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index e9731f1cd4..a636eea285 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -321,10 +321,7 @@ void Area2D::_area_inout(int p_status, const RID &p_area, int p_instance, int p_ void Area2D::_clear_monitoring() { - if (locked) { - ERR_EXPLAIN("This function can't be used during the in/out signal."); - } - ERR_FAIL_COND(locked); + ERR_FAIL_COND_MSG(locked, "This function can't be used during the in/out signal."); { Map<ObjectID, BodyState> bmcopy = body_map; @@ -401,10 +398,7 @@ void Area2D::set_monitoring(bool p_enable) { if (p_enable == monitoring) return; - if (locked) { - ERR_EXPLAIN("Function blocked during in/out signal. Use set_deferred(\"monitoring\",true/false)"); - } - ERR_FAIL_COND(locked); + ERR_FAIL_COND_MSG(locked, "Function blocked during in/out signal. Use set_deferred(\"monitoring\", true/false)."); monitoring = p_enable; @@ -427,10 +421,7 @@ bool Area2D::is_monitoring() const { void Area2D::set_monitorable(bool p_enable) { - if (locked || (is_inside_tree() && Physics2DServer::get_singleton()->is_flushing_queries())) { - ERR_EXPLAIN("Function blocked during in/out signal. Use set_deferred(\"monitorable\",true/false)"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(locked || (is_inside_tree() && Physics2DServer::get_singleton()->is_flushing_queries()), "Function blocked during in/out signal. Use set_deferred(\"monitorable\", true/false)."); if (p_enable == monitorable) return; diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 7368efd21a..b605be47df 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -707,20 +707,14 @@ void CanvasItem::item_rect_changed(bool p_size_changed) { void CanvasItem::draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width, bool p_antialiased) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); VisualServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width, p_antialiased); } void CanvasItem::draw_polyline(const Vector<Point2> &p_points, const Color &p_color, float p_width, bool p_antialiased) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); Vector<Color> colors; colors.push_back(p_color); @@ -729,20 +723,14 @@ void CanvasItem::draw_polyline(const Vector<Point2> &p_points, const Color &p_co void CanvasItem::draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width, bool p_antialiased) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); VisualServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, p_colors, p_width, p_antialiased); } void CanvasItem::draw_multiline(const Vector<Point2> &p_points, const Color &p_color, float p_width, bool p_antialiased) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); Vector<Color> colors; colors.push_back(p_color); @@ -751,20 +739,14 @@ void CanvasItem::draw_multiline(const Vector<Point2> &p_points, const Color &p_c void CanvasItem::draw_multiline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width, bool p_antialiased) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); VisualServer::get_singleton()->canvas_item_add_multiline(canvas_item, p_points, p_colors, p_width, p_antialiased); } void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled, float p_width, bool p_antialiased) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); if (p_filled) { if (p_width != 1.0) { @@ -819,20 +801,14 @@ void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_fil void CanvasItem::draw_circle(const Point2 &p_pos, float p_radius, const Color &p_color) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); VisualServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius, p_color); } void CanvasItem::draw_texture(const Ref<Texture> &p_texture, const Point2 &p_pos, const Color &p_modulate, const Ref<Texture> &p_normal_map) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); ERR_FAIL_COND(p_texture.is_null()); @@ -841,29 +817,20 @@ void CanvasItem::draw_texture(const Ref<Texture> &p_texture, const Point2 &p_pos void CanvasItem::draw_texture_rect(const Ref<Texture> &p_texture, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); ERR_FAIL_COND(p_texture.is_null()); p_texture->draw_rect(canvas_item, p_rect, p_tile, p_modulate, p_transpose, p_normal_map); } void CanvasItem::draw_texture_rect_region(const Ref<Texture> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map, bool p_clip_uv) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); ERR_FAIL_COND(p_texture.is_null()); p_texture->draw_rect_region(canvas_item, p_rect, p_src_rect, p_modulate, p_transpose, p_normal_map, p_clip_uv); } void CanvasItem::draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); ERR_FAIL_COND(p_style_box.is_null()); @@ -871,10 +838,7 @@ void CanvasItem::draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p } void CanvasItem::draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture> p_texture, float p_width, const Ref<Texture> &p_normal_map) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); RID rid_normal = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); @@ -883,10 +847,7 @@ void CanvasItem::draw_primitive(const Vector<Point2> &p_points, const Vector<Col } void CanvasItem::draw_set_transform(const Point2 &p_offset, float p_rot, const Size2 &p_scale) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); Transform2D xform(p_rot, p_offset); xform.scale_basis(p_scale); @@ -895,20 +856,14 @@ void CanvasItem::draw_set_transform(const Point2 &p_offset, float p_rot, const S void CanvasItem::draw_set_transform_matrix(const Transform2D &p_matrix) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item, p_matrix); } void CanvasItem::draw_polygon(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture> p_texture, const Ref<Texture> &p_normal_map, bool p_antialiased) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); RID rid_normal = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); @@ -918,10 +873,7 @@ void CanvasItem::draw_polygon(const Vector<Point2> &p_points, const Vector<Color void CanvasItem::draw_colored_polygon(const Vector<Point2> &p_points, const Color &p_color, const Vector<Point2> &p_uvs, Ref<Texture> p_texture, const Ref<Texture> &p_normal_map, bool p_antialiased) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); Vector<Color> colors; colors.push_back(p_color); @@ -949,10 +901,7 @@ void CanvasItem::draw_multimesh(const Ref<MultiMesh> &p_multimesh, const Ref<Tex void CanvasItem::draw_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, const Color &p_modulate, int p_clip_w) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!drawing, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); ERR_FAIL_COND(p_font.is_null()); p_font->draw(canvas_item, p_pos, p_text, p_modulate, p_clip_w); @@ -960,10 +909,7 @@ void CanvasItem::draw_string(const Ref<Font> &p_font, const Point2 &p_pos, const float CanvasItem::draw_char(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, const String &p_next, const Color &p_modulate) { - if (!drawing) { - ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); - ERR_FAIL_V(0); - } + ERR_FAIL_COND_V_MSG(!drawing, 0, "Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal."); ERR_FAIL_COND_V(p_char.length() != 1, 0); ERR_FAIL_COND_V(p_font.is_null(), 0); diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 936ba777b5..49da709a47 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -157,10 +157,7 @@ void PhysicsBody2D::add_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); PhysicsBody2D *physics_body = Object::cast_to<PhysicsBody2D>(p_node); - if (!physics_body) { - ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type"); - } - ERR_FAIL_COND(!physics_body); + ERR_FAIL_COND_MSG(!physics_body, "Collision exception only works between two objects of PhysicsBody type."); Physics2DServer::get_singleton()->body_add_collision_exception(get_rid(), physics_body->get_rid()); } @@ -168,10 +165,7 @@ void PhysicsBody2D::remove_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); PhysicsBody2D *physics_body = Object::cast_to<PhysicsBody2D>(p_node); - if (!physics_body) { - ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type"); - } - ERR_FAIL_COND(!physics_body); + ERR_FAIL_COND_MSG(!physics_body, "Collision exception only works between two objects of PhysicsBody type."); Physics2DServer::get_singleton()->body_remove_collision_exception(get_rid(), physics_body->get_rid()); } @@ -203,8 +197,7 @@ void StaticBody2D::set_friction(real_t p_friction) { return; } - ERR_EXPLAIN("The method set_friction has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method set_friction has been deprecated and will be removed in the future, use physics material instead."); ERR_FAIL_COND(p_friction < 0 || p_friction > 1); @@ -217,8 +210,7 @@ void StaticBody2D::set_friction(real_t p_friction) { real_t StaticBody2D::get_friction() const { - ERR_EXPLAIN("The method get_friction has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method get_friction has been deprecated and will be removed in the future, use physics material instead."); if (physics_material_override.is_null()) { return 1; @@ -233,8 +225,7 @@ void StaticBody2D::set_bounce(real_t p_bounce) { return; } - ERR_EXPLAIN("The method set_bounce has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method set_bounce has been deprecated and will be removed in the future, use physics material instead."); ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1); @@ -247,8 +238,7 @@ void StaticBody2D::set_bounce(real_t p_bounce) { real_t StaticBody2D::get_bounce() const { - ERR_EXPLAIN("The method get_bounce has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method get_bounce has been deprecated and will be removed in the future, use physics material instead."); if (physics_material_override.is_null()) { return 0; @@ -630,8 +620,7 @@ void RigidBody2D::set_friction(real_t p_friction) { return; } - ERR_EXPLAIN("The method set_friction has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method set_friction has been deprecated and will be removed in the future, use physics material instead."); ERR_FAIL_COND(p_friction < 0 || p_friction > 1); @@ -643,8 +632,7 @@ void RigidBody2D::set_friction(real_t p_friction) { } real_t RigidBody2D::get_friction() const { - ERR_EXPLAIN("The method get_friction has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method get_friction has been deprecated and will be removed in the future, use physics material instead."); if (physics_material_override.is_null()) { return 1; @@ -659,8 +647,7 @@ void RigidBody2D::set_bounce(real_t p_bounce) { return; } - ERR_EXPLAIN("The method set_bounce has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method set_bounce has been deprecated and will be removed in the future, use physics material instead."); ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1); @@ -672,8 +659,7 @@ void RigidBody2D::set_bounce(real_t p_bounce) { } real_t RigidBody2D::get_bounce() const { - ERR_EXPLAIN("The method get_bounce has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method get_bounce has been deprecated and will be removed in the future, use physics material instead."); if (physics_material_override.is_null()) { return 0; @@ -905,10 +891,7 @@ void RigidBody2D::set_contact_monitor(bool p_enabled) { if (!p_enabled) { - if (contact_monitor->locked) { - ERR_EXPLAIN("Can't disable contact monitoring during in/out callback. Use call_deferred(\"set_contact_monitor\",false) instead"); - } - ERR_FAIL_COND(contact_monitor->locked); + ERR_FAIL_COND_MSG(contact_monitor->locked, "Can't disable contact monitoring during in/out callback. Use call_deferred(\"set_contact_monitor\", false) instead."); for (Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) { diff --git a/scene/3d/area.cpp b/scene/3d/area.cpp index 19f43dd274..77682abcb3 100644 --- a/scene/3d/area.cpp +++ b/scene/3d/area.cpp @@ -218,10 +218,7 @@ void Area::_body_inout(int p_status, const RID &p_body, int p_instance, int p_bo void Area::_clear_monitoring() { - if (locked) { - ERR_EXPLAIN("This function can't be used during the in/out signal."); - } - ERR_FAIL_COND(locked); + ERR_FAIL_COND_MSG(locked, "This function can't be used during the in/out signal."); { Map<ObjectID, BodyState> bmcopy = body_map; @@ -291,10 +288,7 @@ void Area::_notification(int p_what) { void Area::set_monitoring(bool p_enable) { - if (locked) { - ERR_EXPLAIN("Function blocked during in/out signal. Use set_deferred(\"monitoring\",true/false)"); - } - ERR_FAIL_COND(locked); + ERR_FAIL_COND_MSG(locked, "Function blocked during in/out signal. Use set_deferred(\"monitoring\", true/false)."); if (p_enable == monitoring) return; @@ -441,10 +435,7 @@ Array Area::get_overlapping_bodies() const { void Area::set_monitorable(bool p_enable) { - if (locked || (is_inside_tree() && PhysicsServer::get_singleton()->is_flushing_queries())) { - ERR_EXPLAIN("Function blocked during in/out signal. Use set_deferred(\"monitorable\",true/false)"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(locked || (is_inside_tree() && PhysicsServer::get_singleton()->is_flushing_queries()), "Function blocked during in/out signal. Use set_deferred(\"monitorable\", true/false)."); if (p_enable == monitorable) return; diff --git a/scene/3d/arvr_nodes.cpp b/scene/3d/arvr_nodes.cpp index 263a2d8de6..4c0449b68e 100644 --- a/scene/3d/arvr_nodes.cpp +++ b/scene/3d/arvr_nodes.cpp @@ -78,10 +78,7 @@ Vector3 ARVRCamera::project_local_ray_normal(const Point2 &p_pos) const { return Camera::project_local_ray_normal(p_pos); } - if (!is_inside_tree()) { - ERR_EXPLAIN("Camera is not inside scene."); - ERR_FAIL_COND_V(!is_inside_tree(), Vector3()); - }; + ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); Size2 viewport_size = get_viewport()->get_camera_rect_size(); Vector2 cpos = get_viewport()->get_camera_coords(p_pos); @@ -106,10 +103,7 @@ Point2 ARVRCamera::unproject_position(const Vector3 &p_pos) const { return Camera::unproject_position(p_pos); } - if (!is_inside_tree()) { - ERR_EXPLAIN("Camera is not inside scene."); - ERR_FAIL_COND_V(!is_inside_tree(), Vector2()); - }; + ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector2(), "Camera is not inside scene."); Size2 viewport_size = get_viewport()->get_visible_rect().size; @@ -138,10 +132,7 @@ Vector3 ARVRCamera::project_position(const Point2 &p_point, float p_z_depth) con return Camera::project_position(p_point, p_z_depth); } - if (!is_inside_tree()) { - ERR_EXPLAIN("Camera is not inside scene."); - ERR_FAIL_COND_V(!is_inside_tree(), Vector3()); - }; + ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); Size2 viewport_size = get_viewport()->get_visible_rect().size; diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index c7d6919a2b..9f8510248c 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -279,10 +279,7 @@ Vector3 Camera::project_ray_normal(const Point2 &p_pos) const { Vector3 Camera::project_local_ray_normal(const Point2 &p_pos) const { - if (!is_inside_tree()) { - ERR_EXPLAIN("Camera is not inside scene."); - ERR_FAIL_COND_V(!is_inside_tree(), Vector3()); - } + ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); Size2 viewport_size = get_viewport()->get_camera_rect_size(); Vector2 cpos = get_viewport()->get_camera_coords(p_pos); @@ -304,10 +301,7 @@ Vector3 Camera::project_local_ray_normal(const Point2 &p_pos) const { Vector3 Camera::project_ray_origin(const Point2 &p_pos) const { - if (!is_inside_tree()) { - ERR_EXPLAIN("Camera is not inside scene."); - ERR_FAIL_COND_V(!is_inside_tree(), Vector3()); - } + ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); Size2 viewport_size = get_viewport()->get_camera_rect_size(); Vector2 cpos = get_viewport()->get_camera_coords(p_pos); @@ -345,10 +339,7 @@ bool Camera::is_position_behind(const Vector3 &p_pos) const { } Vector<Vector3> Camera::get_near_plane_points() const { - if (!is_inside_tree()) { - ERR_EXPLAIN("Camera is not inside scene."); - ERR_FAIL_COND_V(!is_inside_tree(), Vector<Vector3>()); - } + ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector<Vector3>(), "Camera is not inside scene."); Size2 viewport_size = get_viewport()->get_visible_rect().size; @@ -372,10 +363,7 @@ Vector<Vector3> Camera::get_near_plane_points() const { Point2 Camera::unproject_position(const Vector3 &p_pos) const { - if (!is_inside_tree()) { - ERR_EXPLAIN("Camera is not inside scene."); - ERR_FAIL_COND_V(!is_inside_tree(), Vector2()); - } + ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector2(), "Camera is not inside scene."); Size2 viewport_size = get_viewport()->get_visible_rect().size; @@ -400,10 +388,7 @@ Point2 Camera::unproject_position(const Vector3 &p_pos) const { Vector3 Camera::project_position(const Point2 &p_point, float p_z_depth) const { - if (!is_inside_tree()) { - ERR_EXPLAIN("Camera is not inside scene."); - ERR_FAIL_COND_V(!is_inside_tree(), Vector3()); - } + ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); if (p_z_depth == 0) { return get_global_transform().origin; diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index fa2bb300fa..19d5f1dd3c 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -129,10 +129,7 @@ void PhysicsBody::add_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node); - if (!collision_object) { - ERR_EXPLAIN("Collision exception only works between two CollisionObject"); - } - ERR_FAIL_COND(!collision_object); + ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject."); PhysicsServer::get_singleton()->body_add_collision_exception(get_rid(), collision_object->get_rid()); } @@ -140,10 +137,7 @@ void PhysicsBody::remove_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node); - if (!collision_object) { - ERR_EXPLAIN("Collision exception only works between two CollisionObject"); - } - ERR_FAIL_COND(!collision_object); + ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject."); PhysicsServer::get_singleton()->body_remove_collision_exception(get_rid(), collision_object->get_rid()); } @@ -192,8 +186,7 @@ void StaticBody::set_friction(real_t p_friction) { return; } - ERR_EXPLAIN("The method set_friction has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method set_friction has been deprecated and will be removed in the future, use physics material instead."); ERR_FAIL_COND(p_friction < 0 || p_friction > 1); @@ -206,8 +199,7 @@ void StaticBody::set_friction(real_t p_friction) { real_t StaticBody::get_friction() const { - ERR_EXPLAIN("The method get_friction has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method get_friction has been deprecated and will be removed in the future, use physics material instead."); if (physics_material_override.is_null()) { return 1; @@ -222,8 +214,7 @@ void StaticBody::set_bounce(real_t p_bounce) { return; } - ERR_EXPLAIN("The method set_bounce has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method set_bounce has been deprecated and will be removed in the future, use physics material instead."); ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1); @@ -236,8 +227,7 @@ void StaticBody::set_bounce(real_t p_bounce) { real_t StaticBody::get_bounce() const { - ERR_EXPLAIN("The method get_bounce has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method get_bounce has been deprecated and will be removed in the future, use physics material instead."); if (physics_material_override.is_null()) { return 0; @@ -636,8 +626,7 @@ void RigidBody::set_friction(real_t p_friction) { return; } - ERR_EXPLAIN("The method set_friction has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method set_friction has been deprecated and will be removed in the future, use physics material instead."); ERR_FAIL_COND(p_friction < 0 || p_friction > 1); @@ -649,8 +638,7 @@ void RigidBody::set_friction(real_t p_friction) { } real_t RigidBody::get_friction() const { - ERR_EXPLAIN("The method get_friction has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method get_friction has been deprecated and will be removed in the future, use physics material instead."); if (physics_material_override.is_null()) { return 1; @@ -665,8 +653,7 @@ void RigidBody::set_bounce(real_t p_bounce) { return; } - ERR_EXPLAIN("The method set_bounce has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method set_bounce has been deprecated and will be removed in the future, use physics material instead."); ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1); @@ -677,8 +664,7 @@ void RigidBody::set_bounce(real_t p_bounce) { physics_material_override->set_bounce(p_bounce); } real_t RigidBody::get_bounce() const { - ERR_EXPLAIN("The method get_bounce has been deprecated and will be removed in the future, use physics material instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("The method get_bounce has been deprecated and will be removed in the future, use physics material instead."); if (physics_material_override.is_null()) { return 0; } @@ -867,10 +853,7 @@ void RigidBody::set_contact_monitor(bool p_enabled) { if (!p_enabled) { - if (contact_monitor->locked) { - ERR_EXPLAIN("Can't disable contact monitoring during in/out callback. Use call_deferred(\"set_contact_monitor\",false) instead"); - } - ERR_FAIL_COND(contact_monitor->locked); + ERR_FAIL_COND_MSG(contact_monitor->locked, "Can't disable contact monitoring during in/out callback. Use call_deferred(\"set_contact_monitor\", false) instead."); for (Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) { diff --git a/scene/3d/soft_body.cpp b/scene/3d/soft_body.cpp index 386e127f8b..6c3949a0a8 100644 --- a/scene/3d/soft_body.cpp +++ b/scene/3d/soft_body.cpp @@ -577,20 +577,14 @@ Array SoftBody::get_collision_exceptions() { void SoftBody::add_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node); - if (!collision_object) { - ERR_EXPLAIN("Collision exception only works between two CollisionObject"); - } - ERR_FAIL_COND(!collision_object); + ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject."); PhysicsServer::get_singleton()->soft_body_add_collision_exception(physics_rid, collision_object->get_rid()); } void SoftBody::remove_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node); - if (!collision_object) { - ERR_EXPLAIN("Collision exception only works between two CollisionObject"); - } - ERR_FAIL_COND(!collision_object); + ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject."); PhysicsServer::get_singleton()->soft_body_remove_collision_exception(physics_rid, collision_object->get_rid()); } diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index 1a41a31253..df831f92ef 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -684,15 +684,8 @@ void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up) { void Spatial::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up) { - if (p_pos == p_target) { - ERR_EXPLAIN("Node origin and target are in the same position, look_at() failed"); - ERR_FAIL(); - } - - if (p_up.cross(p_target - p_pos) == Vector3()) { - ERR_EXPLAIN("Up vector and direction between node origin and target are aligned, look_at() failed"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(p_pos == p_target, "Node origin and target are in the same position, look_at() failed."); + ERR_FAIL_COND_MSG(p_up.cross(p_target - p_pos) == Vector3(), "Up vector and direction between node origin and target are aligned, look_at() failed."); Transform lookat; lookat.origin = p_pos; diff --git a/scene/animation/animation_cache.cpp b/scene/animation/animation_cache.cpp index 84b3f103c5..e26bd5b5a1 100644 --- a/scene/animation/animation_cache.cpp +++ b/scene/animation/animation_cache.cpp @@ -80,8 +80,7 @@ void AnimationCache::_update_cache() { if (!node) { path_cache.push_back(Path()); - ERR_EXPLAIN("Invalid Track Path in Animation: " + np); - ERR_CONTINUE(!node); + ERR_CONTINUE_MSG(!node, "Invalid track path in animation: " + np + "."); } Path path; @@ -92,8 +91,7 @@ void AnimationCache::_update_cache() { if (np.get_subname_count() > 1) { path_cache.push_back(Path()); - ERR_EXPLAIN("Transform tracks can't have a subpath: " + np); - ERR_CONTINUE(animation->track_get_type(i) == Animation::TYPE_TRANSFORM); + ERR_CONTINUE_MSG(animation->track_get_type(i) == Animation::TYPE_TRANSFORM, "Transform tracks can't have a subpath: " + np + "."); } Spatial *sp = Object::cast_to<Spatial>(node); @@ -101,8 +99,7 @@ void AnimationCache::_update_cache() { if (!sp) { path_cache.push_back(Path()); - ERR_EXPLAIN("Transform track not of type Spatial: " + np); - ERR_CONTINUE(!sp); + ERR_CONTINUE_MSG(!sp, "Transform track not of type Spatial: " + np + "."); } if (np.get_subname_count() == 1) { @@ -113,15 +110,13 @@ void AnimationCache::_update_cache() { if (!sk) { path_cache.push_back(Path()); - ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton!: " + np); - ERR_CONTINUE(!sk); + ERR_CONTINUE_MSG(!sk, "Property defined in Transform track, but not a Skeleton!: " + np + "."); } int idx = sk->find_bone(ps); if (idx == -1) { path_cache.push_back(Path()); - ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton Bone!: " + np); - ERR_CONTINUE(idx == -1); + ERR_CONTINUE_MSG(idx == -1, "Property defined in Transform track, but not a Skeleton Bone!: " + np + "."); } path.bone_idx = idx; @@ -161,8 +156,7 @@ void AnimationCache::_update_cache() { if (np.get_subname_count() == 0) { path_cache.push_back(Path()); - ERR_EXPLAIN("Value Track lacks property: " + np); - ERR_CONTINUE(np.get_subname_count() == 0); + ERR_CONTINUE_MSG(np.get_subname_count() == 0, "Value Track lacks property: " + np + "."); } } else if (animation->track_get_type(i) == Animation::TYPE_METHOD) { @@ -170,8 +164,7 @@ void AnimationCache::_update_cache() { if (path.subpath.size() != 0) { // Trying to call a method of a non-resource path_cache.push_back(Path()); - ERR_EXPLAIN("Method Track has property: " + np); - ERR_CONTINUE(path.subpath.size() != 0); + ERR_CONTINUE_MSG(path.subpath.size() != 0, "Method Track has property: " + np + "."); } } diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index 6e69ee61e3..65bf1e0134 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -317,8 +317,7 @@ float AnimationNodeStateMachinePlayback::process(AnimationNodeStateMachine *p_st if (!playing) { String node_name = start_request; start_request = StringName(); - ERR_EXPLAIN("Can't travel to '" + node_name + "' if state machine is not playing."); - ERR_FAIL_V(0); + ERR_FAIL_V_MSG(0, "Can't travel to '" + node_name + "' if state machine is not playing."); } if (!_travel(p_state_machine, start_request)) { diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 54df346374..30aeebfdac 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -248,10 +248,7 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) { RES resource; Vector<StringName> leftover_path; Node *child = parent->get_node_and_resource(a->track_get_path(i), resource, leftover_path); - if (!child) { - ERR_EXPLAIN("On Animation: '" + p_anim->name + "', couldn't resolve track: '" + String(a->track_get_path(i)) + "'"); - } - ERR_CONTINUE(!child); // couldn't find the child node + ERR_CONTINUE_MSG(!child, "On Animation: '" + p_anim->name + "', couldn't resolve track: '" + String(a->track_get_path(i)) + "'."); // couldn't find the child node uint32_t id = resource.is_valid() ? resource->get_instance_id() : child->get_instance_id(); int bone_idx = -1; @@ -973,8 +970,7 @@ void AnimationPlayer::_animation_process(float p_delta) { Error AnimationPlayer::add_animation(const StringName &p_name, const Ref<Animation> &p_animation) { #ifdef DEBUG_ENABLED - ERR_EXPLAIN("Invalid animation name: " + String(p_name)); - ERR_FAIL_COND_V(String(p_name).find("/") != -1 || String(p_name).find(":") != -1 || String(p_name).find(",") != -1 || String(p_name).find("[") != -1, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(String(p_name).find("/") != -1 || String(p_name).find(":") != -1 || String(p_name).find(",") != -1 || String(p_name).find("[") != -1, ERR_INVALID_PARAMETER, "Invalid animation name: " + String(p_name) + "."); #endif ERR_FAIL_COND_V(p_animation.is_null(), ERR_INVALID_PARAMETER); @@ -1158,10 +1154,7 @@ void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float if (String(name) == "") name = playback.assigned; - if (!animation_set.has(name)) { - ERR_EXPLAIN("Animation not found: " + name); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!animation_set.has(name), "Animation not found: " + name + "."); Playback &c = playback; diff --git a/scene/animation/animation_tree_player.cpp b/scene/animation/animation_tree_player.cpp index 5c3e123ac3..8f6d53c21c 100644 --- a/scene/animation/animation_tree_player.cpp +++ b/scene/animation/animation_tree_player.cpp @@ -403,8 +403,7 @@ void AnimationTreePlayer::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { - ERR_EXPLAIN("AnimationTreePlayer has been deprecated. Use AnimationTree instead."); - WARN_DEPRECATED; + WARN_DEPRECATED_MSG("AnimationTreePlayer has been deprecated. Use AnimationTree instead."); if (!processing) { //make sure that a previous process state was not saved @@ -993,10 +992,9 @@ int AnimationTreePlayer::node_get_input_count(const StringName &p_node) const { ERR_FAIL_COND_V(!node_map.has(p_node), -1); return node_map[p_node]->inputs.size(); } -#define GET_NODE(m_type, m_cast) \ - ERR_FAIL_COND(!node_map.has(p_node)); \ - ERR_EXPLAIN("Invalid parameter for node type."); \ - ERR_FAIL_COND(node_map[p_node]->type != m_type); \ +#define GET_NODE(m_type, m_cast) \ + ERR_FAIL_COND(!node_map.has(p_node)); \ + ERR_FAIL_COND_MSG(node_map[p_node]->type != m_type, "Invalid parameter for node type."); \ m_cast *n = static_cast<m_cast *>(node_map[p_node]); void AnimationTreePlayer::animation_node_set_animation(const StringName &p_node, const Ref<Animation> &p_animation) { @@ -1209,10 +1207,9 @@ Point2 AnimationTreePlayer::node_get_position(const StringName &p_node) const { return node_map[p_node]->pos; } -#define GET_NODE_V(m_type, m_cast, m_ret) \ - ERR_FAIL_COND_V(!node_map.has(p_node), m_ret); \ - ERR_EXPLAIN("Invalid parameter for node type."); \ - ERR_FAIL_COND_V(node_map[p_node]->type != m_type, m_ret); \ +#define GET_NODE_V(m_type, m_cast, m_ret) \ + ERR_FAIL_COND_V(!node_map.has(p_node), m_ret); \ + ERR_FAIL_COND_V_MSG(node_map[p_node]->type != m_type, m_ret, "Invalid parameter for node type."); \ m_cast *n = static_cast<m_cast *>(node_map[p_node]); Ref<Animation> AnimationTreePlayer::animation_node_get_animation(const StringName &p_node) const { @@ -1367,8 +1364,7 @@ void AnimationTreePlayer::get_node_list(List<StringName> *p_node_list) const { void AnimationTreePlayer::remove_node(const StringName &p_node) { ERR_FAIL_COND(!node_map.has(p_node)); - ERR_EXPLAIN("Node 0 (output) can't be removed."); - ERR_FAIL_COND(p_node == out_name); + ERR_FAIL_COND_MSG(p_node == out_name, "Node 0 (output) can't be removed."); for (Map<StringName, NodeBase *>::Element *E = node_map.front(); E; E = E->next()) { diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 4dee4e1d12..2609924f33 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -1185,35 +1185,29 @@ bool Tween::_build_interpolation(InterpolateType p_interpolation_type, Object *p // Validate and apply interpolation data // Give it the object - ERR_EXPLAIN("Invalid object provided to Tween!"); - ERR_FAIL_COND_V(p_object == NULL, false); // Is the object real - ERR_FAIL_COND_V(!ObjectDB::instance_validate(p_object), false); // Is the object a valid instance? + ERR_FAIL_COND_V_MSG(p_object == NULL, false, "Invalid object provided to Tween."); + ERR_FAIL_COND_V_MSG(!ObjectDB::instance_validate(p_object), false, "Invalid object provided to Tween."); data.id = p_object->get_instance_id(); // Validate the initial and final values - ERR_EXPLAIN("Initial value type does not match final value type!"); // TODO: Print both types to make debugging easier - ERR_FAIL_COND_V(p_initial_val.get_type() != p_final_val.get_type(), false); // Do the initial and final value types match? + ERR_FAIL_COND_V_MSG(p_initial_val.get_type() != p_final_val.get_type(), false, "Initial value type '" + Variant::get_type_name(p_initial_val.get_type()) + "' does not match final value type '" + Variant::get_type_name(p_final_val.get_type()) + "'."); data.initial_val = p_initial_val; data.final_val = p_final_val; // Check the Duration - ERR_EXPLAIN("Only non-negative duration values allowed in Tweens!"); - ERR_FAIL_COND_V(p_duration < 0, false); // Is the tween duration non-negative + ERR_FAIL_COND_V_MSG(p_duration < 0, false, "Only non-negative duration values allowed in Tweens."); data.duration = p_duration; // Tween Delay - ERR_EXPLAIN("Only non-negative delay values allowed in Tweens!"); - ERR_FAIL_COND_V(p_delay < 0, false); // Is the delay non-negative? + ERR_FAIL_COND_V_MSG(p_delay < 0, false, "Only non-negative delay values allowed in Tweens."); data.delay = p_delay; // Transition type - ERR_EXPLAIN("Invalid transition type provided to Tween"); - ERR_FAIL_COND_V(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, false); // Is the transition type valid + ERR_FAIL_COND_V_MSG(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, false, "Invalid transition type provided to Tween."); data.trans_type = p_trans_type; // Easing type - ERR_EXPLAIN("Invalid easing type provided to Tween"); - ERR_FAIL_COND_V(p_ease_type < 0 || p_ease_type >= EASE_COUNT, false); // Is the easing type valid + ERR_FAIL_COND_V_MSG(p_ease_type < 0 || p_ease_type >= EASE_COUNT, false, "Invalid easing type provided to Tween."); data.ease_type = p_ease_type; // Is the property defined? @@ -1221,8 +1215,7 @@ bool Tween::_build_interpolation(InterpolateType p_interpolation_type, Object *p // Check that the object actually contains the given property bool prop_valid = false; p_object->get_indexed(p_property->get_subnames(), &prop_valid); - ERR_EXPLAIN("Tween target object has no property named: " + p_property->get_concatenated_subnames()); - ERR_FAIL_COND_V(!prop_valid, false); + ERR_FAIL_COND_V_MSG(!prop_valid, false, "Tween target object has no property named: " + p_property->get_concatenated_subnames() + "."); data.key = p_property->get_subnames(); data.concatenated_key = p_property->get_concatenated_subnames(); @@ -1231,8 +1224,7 @@ bool Tween::_build_interpolation(InterpolateType p_interpolation_type, Object *p // Is the method defined? if (p_method) { // Does the object even have the requested method? - ERR_EXPLAIN("Tween target object has no method named: " + *p_method); // TODO: Fix this error message - ERR_FAIL_COND_V(!p_object->has_method(*p_method), false); + ERR_FAIL_COND_V_MSG(!p_object->has_method(*p_method), false, "Tween target object has no method named: " + *p_method + "."); data.key.push_back(*p_method); data.concatenated_key = *p_method; @@ -1301,8 +1293,7 @@ bool Tween::interpolate_callback(Object *p_object, real_t p_duration, String p_c ERR_FAIL_COND_V(p_duration < 0, false); // Check whether the object even has the callback - ERR_EXPLAIN("Object has no callback named: %s" + p_callback); - ERR_FAIL_COND_V(!p_object->has_method(p_callback), false); + ERR_FAIL_COND_V_MSG(!p_object->has_method(p_callback), false, "Object has no callback named: " + p_callback + "."); // Build a new InterpolationData InterpolateData data; @@ -1361,8 +1352,7 @@ bool Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, S ERR_FAIL_COND_V(p_duration < 0, false); // Confirm the callback exists on the object - ERR_EXPLAIN("Object has no callback named: %s" + p_callback); - ERR_FAIL_COND_V(!p_object->has_method(p_callback), false); + ERR_FAIL_COND_V_MSG(!p_object->has_method(p_callback), false, "Object has no callback named: " + p_callback + "."); // Create a new InterpolateData for the callback InterpolateData data; @@ -1505,10 +1495,8 @@ bool Tween::follow_method(Object *p_object, StringName p_method, Variant p_initi ERR_FAIL_COND_V(p_delay < 0, false); // Confirm both objects have the target methods - ERR_EXPLAIN("Object has no method named: %s" + p_method); - ERR_FAIL_COND_V(!p_object->has_method(p_method), false); - ERR_EXPLAIN("Target has no method named: %s" + p_target_method); - ERR_FAIL_COND_V(!p_target->has_method(p_target_method), false); + ERR_FAIL_COND_V_MSG(!p_object->has_method(p_method), false, "Object has no method named: " + p_method + "."); + ERR_FAIL_COND_V_MSG(!p_target->has_method(p_target_method), false, "Target has no method named: " + p_target_method + "."); // Call the method to get the target value Variant::CallError error; @@ -1641,10 +1629,8 @@ bool Tween::targeting_method(Object *p_object, StringName p_method, Object *p_in ERR_FAIL_COND_V(p_delay < 0, false); // Make sure both objects have the given method - ERR_EXPLAIN("Object has no method named: %s" + p_method); - ERR_FAIL_COND_V(!p_object->has_method(p_method), false); - ERR_EXPLAIN("Initial Object has no method named: %s" + p_initial_method); - ERR_FAIL_COND_V(!p_initial->has_method(p_initial_method), false); + ERR_FAIL_COND_V_MSG(!p_object->has_method(p_method), false, "Object has no method named: " + p_method + "."); + ERR_FAIL_COND_V_MSG(!p_initial->has_method(p_initial_method), false, "Initial Object has no method named: " + p_initial_method + "."); // Call the method to get the initial value Variant::CallError error; diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 3246b9f3ec..9b9fc863dd 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1995,12 +1995,7 @@ Control *Control::find_next_valid_focus() const { Node *n = get_node(data.focus_next); if (n) { from = Object::cast_to<Control>(n); - - if (!from) { - - ERR_EXPLAIN("Next focus node is not a control: " + n->get_name()); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!from, NULL, "Next focus node is not a control: " + n->get_name() + "."); } else { return NULL; } @@ -2090,12 +2085,7 @@ Control *Control::find_prev_valid_focus() const { Node *n = get_node(data.focus_prev); if (n) { from = Object::cast_to<Control>(n); - - if (!from) { - - ERR_EXPLAIN("Previous focus node is not a control: " + n->get_name()); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!from, NULL, "Previous focus node is not a control: " + n->get_name() + "."); } else { return NULL; } @@ -2377,12 +2367,7 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) { Node *n = get_node(data.focus_neighbour[p_margin]); if (n) { c = Object::cast_to<Control>(n); - - if (!c) { - - ERR_EXPLAIN("Neighbour focus node is not a control: " + n->get_name()); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!c, NULL, "Neighbor focus node is not a control: " + n->get_name() + "."); } else { return NULL; } diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 222c75b21d..f7bef4ed39 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -592,8 +592,7 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { Ref<InputEventMouseButton> mb = p_ev; if (mb.is_valid()) { - ERR_EXPLAIN("GraphNode must be the child of a GraphEdit node."); - ERR_FAIL_COND(get_parent_control() == NULL); + ERR_FAIL_COND_MSG(get_parent_control() == NULL, "GraphNode must be the child of a GraphEdit node."); if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index ccdc95696c..60a74066a4 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -1405,8 +1405,7 @@ void LineEdit::set_secret_character(const String &p_string) { // An empty string as the secret character would crash the engine // It also wouldn't make sense to use multiple characters as the secret character - ERR_EXPLAIN("Secret character must be exactly one character long (" + itos(p_string.length()) + " characters given)"); - ERR_FAIL_COND(p_string.length() != 1); + ERR_FAIL_COND_MSG(p_string.length() != 1, "Secret character must be exactly one character long (" + itos(p_string.length()) + " characters given)."); secret_character = p_string; update(); diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 2cac345dae..a7c6c5ccab 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -148,11 +148,9 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const { void PopupMenu::_activate_submenu(int over) { Node *n = get_node(items[over].submenu); - ERR_EXPLAIN("Item subnode does not exist: " + items[over].submenu); - ERR_FAIL_COND(!n); + ERR_FAIL_COND_MSG(!n, "Item subnode does not exist: " + items[over].submenu + "."); Popup *pm = Object::cast_to<Popup>(n); - ERR_EXPLAIN("Item subnode is not a Popup: " + items[over].submenu); - ERR_FAIL_COND(!pm); + ERR_FAIL_COND_MSG(!pm, "Item subnode is not a Popup: " + items[over].submenu + "."); if (pm->is_visible_in_tree()) return; //already visible! diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index e709bac377..ed5dd77f53 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -180,12 +180,12 @@ double Range::get_as_ratio() const { float value = CLAMP(get_value(), shared->min, shared->max); double v = Math::log(value) / Math::log((double)2); - return (v - exp_min) / (exp_max - exp_min); + return CLAMP((v - exp_min) / (exp_max - exp_min), 0, 1); } else { float value = CLAMP(get_value(), shared->min, shared->max); - return (value - get_min()) / (get_max() - get_min()); + return CLAMP((value - get_min()) / (get_max() - get_min()), 0, 1); } } diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 81f2f46a80..6c8aa35e3c 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2700,12 +2700,10 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { bool Tree::edit_selected() { TreeItem *s = get_selected(); - ERR_EXPLAIN("No item selected!"); - ERR_FAIL_COND_V(!s, false); + ERR_FAIL_COND_V_MSG(!s, false, "No item selected."); ensure_cursor_is_visible(); int col = get_selected_column(); - ERR_EXPLAIN("No item column selected!"); - ERR_FAIL_INDEX_V(col, columns.size(), false); + ERR_FAIL_INDEX_V_MSG(col, columns.size(), false, "No item column selected."); if (!s->cells[col].editable) return false; diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index 05bd911014..e21e47f8a8 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -60,14 +60,10 @@ Error HTTPRequest::_parse_url(const String &p_url) { use_ssl = true; port = 443; } else { - ERR_EXPLAIN("Malformed URL"); - ERR_FAIL_V(ERR_INVALID_PARAMETER); + ERR_FAIL_V_MSG(ERR_INVALID_PARAMETER, "Malformed URL."); } - if (url.length() < 1) { - ERR_EXPLAIN("URL too short"); - ERR_FAIL_V(ERR_INVALID_PARAMETER); - } + ERR_FAIL_COND_V_MSG(url.length() < 1, ERR_INVALID_PARAMETER, "URL too short."); int slash_pos = url.find("/"); @@ -91,10 +87,7 @@ Error HTTPRequest::_parse_url(const String &p_url) { Error HTTPRequest::request(const String &p_url, const Vector<String> &p_custom_headers, bool p_ssl_validate_domain, HTTPClient::Method p_method, const String &p_request_data) { ERR_FAIL_COND_V(!is_inside_tree(), ERR_UNCONFIGURED); - if (requesting) { - ERR_EXPLAIN("HTTPRequest is processing a request. Wait for completion or cancel it before attempting a new one."); - ERR_FAIL_V(ERR_BUSY); - } + ERR_FAIL_COND_V_MSG(requesting, ERR_BUSY, "HTTPRequest is processing a request. Wait for completion or cancel it before attempting a new one."); if (timeout > 0) { timer->stop(); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index beb7356bc7..0aaba5491a 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -327,14 +327,9 @@ void Node::_propagate_exit_tree() { void Node::move_child(Node *p_child, int p_pos) { ERR_FAIL_NULL(p_child); - ERR_EXPLAIN("Invalid new child position: " + itos(p_pos)); - ERR_FAIL_INDEX(p_pos, data.children.size() + 1); - ERR_EXPLAIN("child is not a child of this node."); - ERR_FAIL_COND(p_child->data.parent != this); - if (data.blocked > 0) { - ERR_EXPLAIN("Parent node is busy setting up children, move_child() failed. Consider using call_deferred(\"move_child\") instead (or \"popup\" if this is from a popup)."); - ERR_FAIL_COND(data.blocked > 0); - } + ERR_FAIL_INDEX_MSG(p_pos, data.children.size() + 1, "Invalid new child position: " + itos(p_pos) + "."); + ERR_FAIL_COND_MSG(p_child->data.parent != this, "Child is not a child of this node."); + ERR_FAIL_COND_MSG(data.blocked > 0, "Parent node is busy setting up children, move_child() failed. Consider using call_deferred(\"move_child\") instead (or \"popup\" if this is from a popup)."); // Specifying one place beyond the end // means the same as moving to the last position @@ -1165,25 +1160,9 @@ void Node::_add_child_nocheck(Node *p_child, const StringName &p_name) { void Node::add_child(Node *p_child, bool p_legible_unique_name) { ERR_FAIL_NULL(p_child); - - if (p_child == this) { - ERR_EXPLAIN("Can't add child '" + p_child->get_name() + "' to itself."); - ERR_FAIL_COND(p_child == this); // adding to itself! - } - - /* Fail if node has a parent */ - if (p_child->data.parent) { - ERR_EXPLAIN("Can't add child '" + p_child->get_name() + "' to '" + get_name() + "', already has a parent '" + p_child->data.parent->get_name() + "'."); - ERR_FAIL_COND(p_child->data.parent); - } - - if (data.blocked > 0) { - ERR_EXPLAIN("Parent node is busy setting up children, add_node() failed. Consider using call_deferred(\"add_child\", child) instead."); - ERR_FAIL_COND(data.blocked > 0); - } - - ERR_EXPLAIN("Can't add child while a notification is happening."); - ERR_FAIL_COND(data.blocked > 0); + ERR_FAIL_COND_MSG(p_child == this, "Can't add child '" + p_child->get_name() + "' to itself."); // adding to itself! + ERR_FAIL_COND_MSG(p_child->data.parent, "Can't add child '" + p_child->get_name() + "' to '" + get_name() + "', already has a parent '" + p_child->data.parent->get_name() + "'."); //Fail if node has a parent + ERR_FAIL_COND_MSG(data.blocked > 0, "Parent node is busy setting up children, add_node() failed. Consider using call_deferred(\"add_child\", child) instead."); /* Validate name */ _validate_child_name(p_child, p_legible_unique_name); @@ -1239,10 +1218,7 @@ void Node::_propagate_validate_owner() { void Node::remove_child(Node *p_child) { ERR_FAIL_NULL(p_child); - if (data.blocked > 0) { - ERR_EXPLAIN("Parent node is busy setting up children, remove_node() failed. Consider using call_deferred(\"remove_child\",child) instead."); - ERR_FAIL_COND(data.blocked > 0); - } + ERR_FAIL_COND_MSG(data.blocked > 0, "Parent node is busy setting up children, remove_node() failed. Consider using call_deferred(\"remove_child\", child) instead."); int child_count = data.children.size(); Node **children = data.children.ptrw(); @@ -1265,8 +1241,7 @@ void Node::remove_child(Node *p_child) { } } - ERR_EXPLAIN("Cannot remove child node " + p_child->to_string() + " as it is not in our list of children"); - ERR_FAIL_COND(idx == -1); + ERR_FAIL_COND_MSG(idx == -1, "Cannot remove child node " + p_child->get_name() + " as it is not a child of this node."); //ERR_FAIL_COND( p_child->data.blocked > 0 ); //if (data.scene) { does not matter @@ -1330,10 +1305,7 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { return NULL; } - if (!data.inside_tree && p_path.is_absolute()) { - ERR_EXPLAIN("Can't use get_node() with absolute paths from outside the active scene tree."); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!data.inside_tree && p_path.is_absolute(), NULL, "Can't use get_node() with absolute paths from outside the active scene tree."); Node *current = NULL; Node *root = NULL; @@ -1394,10 +1366,7 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { Node *Node::get_node(const NodePath &p_path) const { Node *node = get_node_or_null(p_path); - if (!node) { - ERR_EXPLAIN("Node not found: " + p_path); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!node, NULL, "Node not found: " + p_path + "."); return node; } @@ -1665,8 +1634,7 @@ NodePath Node::get_path_to(const Node *p_node) const { NodePath Node::get_path() const { - ERR_EXPLAIN("Cannot get path of node as it is not in a scene tree"); - ERR_FAIL_COND_V(!is_inside_tree(), NodePath()); + ERR_FAIL_COND_V_MSG(!is_inside_tree(), NodePath(), "Cannot get path of node as it is not in a scene tree."); if (data.path_cache) return *data.path_cache; @@ -2193,13 +2161,11 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p } else { Object *obj = ClassDB::instance(get_class()); - ERR_EXPLAIN("Node: Could not duplicate: " + String(get_class())); - ERR_FAIL_COND(!obj); + ERR_FAIL_COND_MSG(!obj, "Node: Could not duplicate: " + String(get_class()) + "."); node = Object::cast_to<Node>(obj); if (!node) { memdelete(obj); - ERR_EXPLAIN("Node: Could not duplicate: " + String(get_class())); - ERR_FAIL(); + ERR_FAIL_MSG("Node: Could not duplicate: " + String(get_class()) + "."); } } @@ -2297,14 +2263,12 @@ Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const { ERR_FAIL_COND_V(get_filename() != "", NULL); Object *obj = ClassDB::instance(get_class()); - ERR_EXPLAIN("Node: Could not duplicate: " + String(get_class())); - ERR_FAIL_COND_V(!obj, NULL); + ERR_FAIL_COND_V_MSG(!obj, NULL, "Node: Could not duplicate: " + String(get_class()) + "."); Node *node = Object::cast_to<Node>(obj); if (!node) { memdelete(obj); - ERR_EXPLAIN("Node: Could not duplicate: " + String(get_class())); - ERR_FAIL_V(NULL); + ERR_FAIL_V_MSG(NULL, "Node: Could not duplicate: " + String(get_class()) + "."); } node->set_name(get_name()); @@ -2441,8 +2405,7 @@ void Node::_replace_connections_target(Node *p_new_target) { if (c.flags & CONNECT_PERSIST) { c.source->disconnect(c.signal, this, c.method); bool valid = p_new_target->has_method(c.method) || Ref<Script>(p_new_target->get_script()).is_null() || Ref<Script>(p_new_target->get_script())->has_method(c.method); - ERR_EXPLAIN("Attempt to connect signal \'" + c.source->get_class() + "." + c.signal + "\' to nonexistent method \'" + c.target->get_class() + "." + c.method + "\'"); - ERR_CONTINUE(!valid); + ERR_CONTINUE_MSG(!valid, "Attempt to connect signal '" + c.source->get_class() + "." + c.signal + "' to nonexistent method '" + c.target->get_class() + "." + c.method + "'."); c.source->connect(c.signal, p_new_target, c.method, c.binds, c.flags); } } diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 2668acd3d5..98d63650d3 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -116,10 +116,7 @@ SceneTree::Group *SceneTree::add_to_group(const StringName &p_group, Node *p_nod E = group_map.insert(p_group, Group()); } - if (E->get().nodes.find(p_node) != -1) { - ERR_EXPLAIN("Already in group: " + p_group); - ERR_FAIL_V(&E->get()); - } + ERR_FAIL_COND_V_MSG(E->get().nodes.find(p_node) != -1, &E->get(), "Already in group: " + p_group + "."); E->get().nodes.push_back(p_node); //E->get().last_tree_version=0; E->get().changed = true; diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index 2ae950dad5..03d46fd28d 100755 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp @@ -80,8 +80,7 @@ void Timer::_notification(int p_what) { } void Timer::set_wait_time(float p_time) { - ERR_EXPLAIN("time should be greater than zero."); - ERR_FAIL_COND(p_time <= 0); + ERR_FAIL_COND_MSG(p_time <= 0, "Time should be greater than zero."); wait_time = p_time; } float Timer::get_wait_time() const { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 9466b7c5c1..93eea2ad0b 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -65,13 +65,11 @@ void ViewportTexture::setup_local_to_scene() { } Node *vpn = local_scene->get_node(path); - ERR_EXPLAIN("ViewportTexture: Path to node is invalid"); - ERR_FAIL_COND(!vpn); + ERR_FAIL_COND_MSG(!vpn, "ViewportTexture: Path to node is invalid."); vp = Object::cast_to<Viewport>(vpn); - ERR_EXPLAIN("ViewportTexture: Path to node does not point to a viewport"); - ERR_FAIL_COND(!vp); + ERR_FAIL_COND_MSG(!vp, "ViewportTexture: Path to node does not point to a viewport."); vp->viewport_textures.insert(this); @@ -2393,8 +2391,7 @@ void Viewport::_gui_remove_from_modal_stack(List<Control *>::Element *MI, Object void Viewport::_gui_force_drag(Control *p_base, const Variant &p_data, Control *p_control) { - ERR_EXPLAIN("Drag data must be a value"); - ERR_FAIL_COND(p_data.get_type() == Variant::NIL); + ERR_FAIL_COND_MSG(p_data.get_type() == Variant::NIL, "Drag data must be a value."); gui.dragging = true; gui.drag_data = p_data; diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index cb710dde43..bb14cf3ab1 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -765,10 +765,7 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const { //validate// int pc = baked_point_cache.size(); - if (pc == 0) { - ERR_EXPLAIN("No points in Curve2D."); - ERR_FAIL_V(Vector2()); - } + ERR_FAIL_COND_V_MSG(pc == 0, Vector2(), "No points in Curve2D."); if (pc == 1) return baked_point_cache.get(0); @@ -831,10 +828,7 @@ Vector2 Curve2D::get_closest_point(const Vector2 &p_to_point) const { //validate// int pc = baked_point_cache.size(); - if (pc == 0) { - ERR_EXPLAIN("No points in Curve2D."); - ERR_FAIL_V(Vector2()); - } + ERR_FAIL_COND_V_MSG(pc == 0, Vector2(), "No points in Curve2D."); if (pc == 1) return baked_point_cache.get(0); @@ -870,10 +864,7 @@ float Curve2D::get_closest_offset(const Vector2 &p_to_point) const { //validate// int pc = baked_point_cache.size(); - if (pc == 0) { - ERR_EXPLAIN("No points in Curve2D."); - ERR_FAIL_V(0.0f); - } + ERR_FAIL_COND_V_MSG(pc == 0, 0.0f, "No points in Curve2D."); if (pc == 1) return 0.0f; @@ -1336,10 +1327,7 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const { //validate// int pc = baked_point_cache.size(); - if (pc == 0) { - ERR_EXPLAIN("No points in Curve3D."); - ERR_FAIL_V(Vector3()); - } + ERR_FAIL_COND_V_MSG(pc == 0, Vector3(), "No points in Curve3D."); if (pc == 1) return baked_point_cache.get(0); @@ -1381,10 +1369,7 @@ float Curve3D::interpolate_baked_tilt(float p_offset) const { //validate// int pc = baked_tilt_cache.size(); - if (pc == 0) { - ERR_EXPLAIN("No tilts in Curve3D."); - ERR_FAIL_V(0); - } + ERR_FAIL_COND_V_MSG(pc == 0, 0, "No tilts in Curve3D."); if (pc == 1) return baked_tilt_cache.get(0); @@ -1420,10 +1405,7 @@ Vector3 Curve3D::interpolate_baked_up_vector(float p_offset, bool p_apply_tilt) //validate// // curve may not have baked up vectors int count = baked_up_vector_cache.size(); - if (count == 0) { - ERR_EXPLAIN("No up vectors in Curve3D."); - ERR_FAIL_V(Vector3(0, 1, 0)); - } + ERR_FAIL_COND_V_MSG(count == 0, Vector3(0, 1, 0), "No up vectors in Curve3D."); if (count == 1) return baked_up_vector_cache.get(0); @@ -1491,10 +1473,7 @@ Vector3 Curve3D::get_closest_point(const Vector3 &p_to_point) const { //validate// int pc = baked_point_cache.size(); - if (pc == 0) { - ERR_EXPLAIN("No points in Curve3D."); - ERR_FAIL_V(Vector3()); - } + ERR_FAIL_COND_V_MSG(pc == 0, Vector3(), "No points in Curve3D."); if (pc == 1) return baked_point_cache.get(0); @@ -1530,10 +1509,7 @@ float Curve3D::get_closest_offset(const Vector3 &p_to_point) const { //validate// int pc = baked_point_cache.size(); - if (pc == 0) { - ERR_EXPLAIN("No points in Curve3D."); - ERR_FAIL_V(0.0f); - } + ERR_FAIL_COND_V_MSG(pc == 0, 0.0f, "No points in Curve3D."); if (pc == 1) return 0.0f; diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 58fd883b0d..df8d4a7fed 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -118,8 +118,7 @@ Error DynamicFontAtSize::_load() { int error = FT_Init_FreeType(&library); - ERR_EXPLAIN(TTR("Error initializing FreeType.")); - ERR_FAIL_COND_V(error != 0, ERR_CANT_CREATE); + ERR_FAIL_COND_V_MSG(error != 0, ERR_CANT_CREATE, "Error initializing FreeType."); // FT_OPEN_STREAM is extremely slow only on Android. if (OS::get_singleton()->get_name() == "Android" && font->font_mem == NULL && font->font_path != String()) { @@ -177,19 +176,18 @@ Error DynamicFontAtSize::_load() { error = FT_Open_Face(library, &fargs, 0, &face); } else { - ERR_EXPLAIN("DynamicFont uninitialized"); - ERR_FAIL_V(ERR_UNCONFIGURED); + ERR_FAIL_V_MSG(ERR_UNCONFIGURED, "DynamicFont uninitialized."); } //error = FT_New_Face( library, src_path.utf8().get_data(),0,&face ); if (error == FT_Err_Unknown_File_Format) { - ERR_EXPLAIN(TTR("Unknown font format.")); + ERR_EXPLAIN("Unknown font format."); FT_Done_FreeType(library); } else if (error) { - ERR_EXPLAIN(TTR("Error loading font.")); + ERR_EXPLAIN("Error loading font."); FT_Done_FreeType(library); } @@ -509,8 +507,7 @@ DynamicFontAtSize::Character DynamicFontAtSize::_bitmap_to_character(FT_Bitmap b } break; // TODO: FT_PIXEL_MODE_LCD default: - ERR_EXPLAIN("Font uses unsupported pixel format: " + itos(bitmap.pixel_mode)); - ERR_FAIL_V(Character::not_found()); + ERR_FAIL_V_MSG(Character::not_found(), "Font uses unsupported pixel format: " + itos(bitmap.pixel_mode) + "."); break; } } diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index a29e25174d..cff77acdd7 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -202,10 +202,7 @@ Error BitmapFont::create_from_fnt(const String &p_file) { FileAccess *f = FileAccess::open(p_file, FileAccess::READ); - if (!f) { - ERR_EXPLAIN("Can't open font: " + p_file); - ERR_FAIL_V(ERR_FILE_NOT_FOUND); - } + ERR_FAIL_COND_V_MSG(!f, ERR_FILE_NOT_FOUND, "Can't open font: " + p_file + "."); clear(); @@ -532,10 +529,7 @@ Size2 Font::get_wordwrap_string_size(const String &p_string, float p_width) cons void BitmapFont::set_fallback(const Ref<BitmapFont> &p_fallback) { for (Ref<BitmapFont> fallback_child = p_fallback; fallback_child != NULL; fallback_child = fallback_child->get_fallback()) { - if (fallback_child == this) { - ERR_EXPLAIN("Can't set as fallback one of its parents to prevent crashes due to recursive loop."); - ERR_FAIL_COND(fallback_child == this); - } + ERR_FAIL_COND_MSG(fallback_child == this, "Can't set as fallback one of its parents to prevent crashes due to recursive loop."); } fallback = p_fallback; diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 44bc862198..daa51aabd7 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -39,10 +39,7 @@ void Material::set_next_pass(const Ref<Material> &p_pass) { for (Ref<Material> pass_child = p_pass; pass_child != NULL; pass_child = pass_child->get_next_pass()) { - if (pass_child == this) { - ERR_EXPLAIN("Can't set as next_pass one of its parents to prevent crashes due to recursive loop."); - ERR_FAIL_COND(pass_child == this); - } + ERR_FAIL_COND_MSG(pass_child == this, "Can't set as next_pass one of its parents to prevent crashes due to recursive loop."); } if (next_pass == p_pass) diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index aff274cd21..4afb07cb6f 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -883,10 +883,7 @@ int ArrayMesh::get_surface_count() const { void ArrayMesh::add_blend_shape(const StringName &p_name) { - if (surfaces.size()) { - ERR_EXPLAIN("Can't add a shape key count if surfaces are already created."); - ERR_FAIL_COND(surfaces.size()); - } + ERR_FAIL_COND_MSG(surfaces.size(), "Can't add a shape key count if surfaces are already created."); StringName name = p_name; @@ -914,10 +911,7 @@ StringName ArrayMesh::get_blend_shape_name(int p_index) const { } void ArrayMesh::clear_blend_shapes() { - if (surfaces.size()) { - ERR_EXPLAIN("Can't set shape key count if surfaces are already created."); - ERR_FAIL_COND(surfaces.size()); - } + ERR_FAIL_COND_MSG(surfaces.size(), "Can't set shape key count if surfaces are already created."); blend_shapes.clear(); } @@ -1109,8 +1103,7 @@ struct ArrayMeshLightmapSurface { Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texel_size) { ERR_FAIL_COND_V(!array_mesh_lightmap_unwrap_callback, ERR_UNCONFIGURED); - ERR_EXPLAIN("Can't unwrap mesh with blend shapes"); - ERR_FAIL_COND_V(blend_shapes.size() != 0, ERR_UNAVAILABLE); + ERR_FAIL_COND_V_MSG(blend_shapes.size() != 0, ERR_UNAVAILABLE, "Can't unwrap mesh with blend shapes."); Vector<float> vertices; Vector<float> normals; @@ -1124,15 +1117,9 @@ Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texe ArrayMeshLightmapSurface s; s.primitive = surface_get_primitive_type(i); - if (s.primitive != Mesh::PRIMITIVE_TRIANGLES) { - ERR_EXPLAIN("Only triangles are supported for lightmap unwrap"); - ERR_FAIL_V(ERR_UNAVAILABLE); - } + ERR_FAIL_COND_V_MSG(s.primitive != Mesh::PRIMITIVE_TRIANGLES, ERR_UNAVAILABLE, "Only triangles are supported for lightmap unwrap."); s.format = surface_get_format(i); - if (!(s.format & ARRAY_FORMAT_NORMAL)) { - ERR_EXPLAIN("Normals are required for lightmap unwrap"); - ERR_FAIL_V(ERR_UNAVAILABLE); - } + ERR_FAIL_COND_V_MSG(!(s.format & ARRAY_FORMAT_NORMAL), ERR_UNAVAILABLE, "Normals are required for lightmap unwrap."); Array arrays = surface_get_arrays(i); s.material = surface_get_material(i); diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 99286668ce..7d62873bbd 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -92,8 +92,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const { if (i > 0) { - ERR_EXPLAIN(vformat("Invalid scene: node %s does not specify its parent node.", snames[n.name])); - ERR_FAIL_COND_V(n.parent == -1, NULL); + ERR_FAIL_COND_V_MSG(n.parent == -1, NULL, vformat("Invalid scene: node %s does not specify its parent node.", snames[n.name])); NODE_FROM_ID(nparent, n.parent); #ifdef DEBUG_ENABLED if (!nparent && (n.parent & FLAG_ID_IS_PATH)) { @@ -1093,10 +1092,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { if (p_dictionary.has("version")) version = p_dictionary["version"]; - if (version > PACK_VERSION) { - ERR_EXPLAIN("Save format version too new!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(version > PACK_VERSION, "Save format version too new."); PoolVector<String> snames = p_dictionary["names"]; if (snames.size()) { @@ -1690,10 +1686,7 @@ bool PackedScene::can_instance() const { Node *PackedScene::instance(GenEditState p_edit_state) const { #ifndef TOOLS_ENABLED - if (p_edit_state != GEN_EDIT_STATE_DISABLED) { - ERR_EXPLAIN("Edit state is only for editors, does not work without tools compiled"); - ERR_FAIL_COND_V(p_edit_state != GEN_EDIT_STATE_DISABLED, NULL); - } + ERR_FAIL_COND_V_MSG(p_edit_state != GEN_EDIT_STATE_DISABLED, NULL, "Edit state is only for editors, does not work without tools compiled."); #endif Node *s = state->instance((SceneState::GenEditState)p_edit_state); diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index 6212066c3c..cd229732ba 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -1366,8 +1366,7 @@ String ResourceFormatSaverTextInstance::_write_resource(const RES &res) { String path = relative_paths ? local_path.path_to_file(res->get_path()) : res->get_path(); return "Resource( \"" + path + "\" )"; } else { - ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?"); - ERR_FAIL_V("null"); + ERR_FAIL_V_MSG("null", "Resource was not pre cached for the resource section, bug?"); //internal resource } } diff --git a/scene/resources/text_file.cpp b/scene/resources/text_file.cpp index 37bdd691b4..b84f3f1f9e 100644 --- a/scene/resources/text_file.cpp +++ b/scene/resources/text_file.cpp @@ -67,10 +67,7 @@ Error TextFile::load_text(const String &p_path) { w[len] = 0; String s; - if (s.parse_utf8((const char *)w.ptr())) { - ERR_EXPLAIN("Script '" + p_path + "' contains invalid unicode (utf-8), so it was not loaded. Please ensure that scripts are saved in valid utf-8 unicode."); - ERR_FAIL_V(ERR_INVALID_DATA); - } + ERR_FAIL_COND_V_MSG(s.parse_utf8((const char *)w.ptr()), ERR_INVALID_DATA, "Script '" + p_path + "' contains invalid unicode (UTF-8), so it was not loaded. Please ensure that scripts are saved in valid UTF-8 unicode."); text = s; path = p_path; return OK; diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index a5e9351753..e44b17584b 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -2351,8 +2351,7 @@ RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String texarr.instance(); lt = texarr; } else { - ERR_EXPLAIN("Unrecognized layered texture extension"); - ERR_FAIL_V(RES()); + ERR_FAIL_V_MSG(RES(), "Unrecognized layered texture extension."); } FileAccess *f = FileAccess::open(p_path, FileAccess::READ); @@ -2373,8 +2372,7 @@ RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String } } else { - ERR_EXPLAIN("Unrecognized layered texture file format: " + String((const char *)header)); - ERR_FAIL_V(RES()); + ERR_FAIL_V_MSG(RES(), "Unrecognized layered texture file format: " + String((const char *)header) + "."); } int tw = f->get_32(); diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index eed255fd6e..24122a8d99 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -1006,8 +1006,7 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) { s.autotile_coord = default_autotile_coord; } else { - ERR_EXPLAIN("Expected an array of objects or dictionaries for tile_set_shapes"); - ERR_CONTINUE(true); + ERR_CONTINUE_MSG(true, "Expected an array of objects or dictionaries for tile_set_shapes."); } shapes_data.push_back(s); diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 843e33f11e..cd0c1b5b07 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -307,11 +307,7 @@ Error VisualShader::connect_nodes(Type p_type, int p_from_node, int p_from_port, VisualShaderNode::PortType from_port_type = g->nodes[p_from_node].node->get_output_port_type(p_from_port); VisualShaderNode::PortType to_port_type = g->nodes[p_to_node].node->get_input_port_type(p_to_port); - if (!is_port_types_compatible(from_port_type, to_port_type)) { - ERR_EXPLAIN("Incompatible port types (scalar/vec/bool) with transform"); - ERR_FAIL_V(ERR_INVALID_PARAMETER); - return ERR_INVALID_PARAMETER; - } + ERR_FAIL_COND_V_MSG(!is_port_types_compatible(from_port_type, to_port_type), ERR_INVALID_PARAMETER, "Incompatible port types (scalar/vec/bool) with transform."); for (List<Connection>::Element *E = g->connections.front(); E; E = E->next()) { diff --git a/servers/audio/effects/audio_effect_record.cpp b/servers/audio/effects/audio_effect_record.cpp index acf27d2bbf..1390ab55c4 100644 --- a/servers/audio/effects/audio_effect_record.cpp +++ b/servers/audio/effects/audio_effect_record.cpp @@ -217,7 +217,7 @@ Ref<AudioStreamSample> AudioEffectRecord::get_recording() const { PoolVector<uint8_t> dst_data; ERR_FAIL_COND_V(current_instance.is_null(), NULL); - ERR_FAIL_COND_V(current_instance->recording_data.size(), NULL); + ERR_FAIL_COND_V(current_instance->recording_data.size() == 0, NULL); if (dst_format == AudioStreamSample::FORMAT_8_BITS) { int data_size = current_instance->recording_data.size(); diff --git a/servers/audio/voice_rb_sw.h b/servers/audio/voice_rb_sw.h index 0a39c536ae..1f0c88ed30 100644 --- a/servers/audio/voice_rb_sw.h +++ b/servers/audio/voice_rb_sw.h @@ -125,8 +125,7 @@ public: if (full) { #ifdef DEBUG_ENABLED if (OS::get_singleton()->is_stdout_verbose()) { - ERR_EXPLAIN("Audio Ring Buffer Full (too many commands"); - ERR_FAIL_COND(((write_pos + 1) % VOICE_RB_SIZE) == read_pos); + ERR_FAIL_COND_MSG(((write_pos + 1) % VOICE_RB_SIZE) == read_pos, "Audio ring buffer full (too many commands)."); } #endif return; diff --git a/servers/physics/collision_object_sw.h b/servers/physics/collision_object_sw.h index 895eda8528..b9912f0ba2 100644 --- a/servers/physics/collision_object_sw.h +++ b/servers/physics/collision_object_sw.h @@ -86,13 +86,9 @@ protected: void _unregister_shapes(); _FORCE_INLINE_ void _set_transform(const Transform &p_transform, bool p_update_shapes = true) { - #ifdef DEBUG_ENABLED - if (p_transform.origin.length_squared() > MAX_OBJECT_DISTANCE_X2) { - ERR_EXPLAIN("Object went too far away (more than " + itos(MAX_OBJECT_DISTANCE) + "mts from origin)."); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(p_transform.origin.length_squared() > MAX_OBJECT_DISTANCE_X2, "Object went too far away (more than " + itos(MAX_OBJECT_DISTANCE) + " units from origin)."); #endif transform = p_transform; diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index 7b982e7015..09872977b6 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -40,11 +40,8 @@ #include "joints/pin_joint_sw.h" #include "joints/slider_joint_sw.h" -#define FLUSH_QUERY_CHECK(m_object) \ - if (m_object->get_space() && flushing_queries) { \ - ERR_EXPLAIN("Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead"); \ - ERR_FAIL(); \ - } +#define FLUSH_QUERY_CHECK(m_object) \ + ERR_FAIL_COND_MSG(m_object->get_space() && flushing_queries, "Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead."); RID PhysicsServerSW::shape_create(ShapeType p_shape) { @@ -73,8 +70,7 @@ RID PhysicsServerSW::shape_create(ShapeType p_shape) { } break; case SHAPE_CYLINDER: { - ERR_EXPLAIN("CylinderShape is not supported in GodotPhysics. Please switch to Bullet in the Project Settings."); - ERR_FAIL_V(RID()); + ERR_FAIL_V_MSG(RID(), "CylinderShape is not supported in GodotPhysics. Please switch to Bullet in the Project Settings."); } break; case SHAPE_CONVEX_POLYGON: { @@ -200,11 +196,7 @@ PhysicsDirectSpaceState *PhysicsServerSW::space_get_direct_state(RID p_space) { SpaceSW *space = space_owner.get(p_space); ERR_FAIL_COND_V(!space, NULL); - if (!doing_sync || space->is_locked()) { - - ERR_EXPLAIN("Space state is inaccessible right now, wait for iteration or physics process notification."); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!doing_sync || space->is_locked(), NULL, "Space state is inaccessible right now, wait for iteration or physics process notification."); return space->get_direct_state(); } @@ -987,12 +979,7 @@ PhysicsDirectBodyState *PhysicsServerSW::body_get_direct_state(RID p_body) { BodySW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body, NULL); - - if (!doing_sync || body->get_space()->is_locked()) { - - ERR_EXPLAIN("Body state is inaccessible right now, wait for iteration or physics process notification."); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(!doing_sync || body->get_space()->is_locked(), NULL, "Body state is inaccessible right now, wait for iteration or physics process notification."); direct_state->body = body; return direct_state; @@ -1410,8 +1397,7 @@ void PhysicsServerSW::free(RID p_rid) { } else { - ERR_EXPLAIN("Invalid ID"); - ERR_FAIL(); + ERR_FAIL_MSG("Invalid ID."); } }; diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index cc656d3b73..80e204087a 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -36,11 +36,8 @@ #include "core/project_settings.h" #include "core/script_language.h" -#define FLUSH_QUERY_CHECK(m_object) \ - if (m_object->get_space() && flushing_queries) { \ - ERR_EXPLAIN("Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead"); \ - ERR_FAIL(); \ - } +#define FLUSH_QUERY_CHECK(m_object) \ + ERR_FAIL_COND_MSG(m_object->get_space() && flushing_queries, "Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead."); RID Physics2DServerSW::_shape_create(ShapeType p_shape) { @@ -316,11 +313,7 @@ Physics2DDirectSpaceState *Physics2DServerSW::space_get_direct_state(RID p_space Space2DSW *space = space_owner.get(p_space); ERR_FAIL_COND_V(!space, NULL); - if ((using_threads && !doing_sync) || space->is_locked()) { - - ERR_EXPLAIN("Space state is inaccessible right now, wait for iteration or physics process notification."); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG((using_threads && !doing_sync) || space->is_locked(), NULL, "Space state is inaccessible right now, wait for iteration or physics process notification."); return space->get_direct_state(); } @@ -1075,10 +1068,7 @@ int Physics2DServerSW::body_test_ray_separation(RID p_body, const Transform2D &p Physics2DDirectBodyState *Physics2DServerSW::body_get_direct_state(RID p_body) { - if ((using_threads && !doing_sync)) { - ERR_EXPLAIN("Body state is inaccessible right now, wait for iteration or physics process notification."); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG((using_threads && !doing_sync), NULL, "Body state is inaccessible right now, wait for iteration or physics process notification."); if (!body_owner.owns(p_body)) return NULL; @@ -1086,12 +1076,7 @@ Physics2DDirectBodyState *Physics2DServerSW::body_get_direct_state(RID p_body) { Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body, NULL); ERR_FAIL_COND_V(!body->get_space(), NULL); - - if (body->get_space()->is_locked()) { - - ERR_EXPLAIN("Body state is inaccessible right now, wait for iteration or physics process notification."); - ERR_FAIL_V(NULL); - } + ERR_FAIL_COND_V_MSG(body->get_space()->is_locked(), NULL, "Body state is inaccessible right now, wait for iteration or physics process notification."); direct_state->body = body; return direct_state; @@ -1321,8 +1306,7 @@ void Physics2DServerSW::free(RID p_rid) { } else { - ERR_EXPLAIN("Invalid ID"); - ERR_FAIL(); + ERR_FAIL_MSG("Invalid ID."); } }; diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 5c28705192..5f39d3ff49 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -961,6 +961,7 @@ bool ShaderLanguage::_find_identifier(const BlockNode *p_block, const Map<String if (r_type) { *r_type = IDENTIFIER_FUNCTION; } + return true; } } diff --git a/servers/visual/visual_server_canvas.cpp b/servers/visual/visual_server_canvas.cpp index fc75fda583..f5a1276c27 100644 --- a/servers/visual/visual_server_canvas.cpp +++ b/servers/visual/visual_server_canvas.cpp @@ -386,8 +386,7 @@ void VisualServerCanvas::canvas_item_set_parent(RID p_item, RID p_parent) { } else { - ERR_EXPLAIN("Invalid parent"); - ERR_FAIL(); + ERR_FAIL_MSG("Invalid parent."); } } @@ -754,12 +753,7 @@ void VisualServerCanvas::canvas_item_add_polygon(RID p_item, const Vector<Point2 ERR_FAIL_COND(uv_size != 0 && (uv_size != pointcount)); #endif Vector<int> indices = Geometry::triangulate_polygon(p_points); - - if (indices.empty()) { - - ERR_EXPLAIN("Bad Polygon!"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(indices.empty(), "Invalid polygon data, triangulation failed."); Item::CommandPolygon *polygon = memnew(Item::CommandPolygon); ERR_FAIL_COND(!polygon); diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index 25e18d0623..13fcda2402 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -1145,11 +1145,7 @@ void VisualServer::mesh_add_surface_from_arrays(RID p_mesh, PrimitiveType p_prim Vector<AABB> bone_aabb; Error err = _surface_set_data(p_arrays, format, offsets, total_elem_size, vertex_array, array_len, index_array, index_array_len, aabb, bone_aabb); - - if (err) { - ERR_EXPLAIN("Invalid array format for surface"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(err, "Invalid array format for surface."); Vector<PoolVector<uint8_t> > blend_shape_data; @@ -1162,10 +1158,7 @@ void VisualServer::mesh_add_surface_from_arrays(RID p_mesh, PrimitiveType p_prim AABB laabb; Error err2 = _surface_set_data(p_blend_shapes[i], format & ~ARRAY_FORMAT_INDEX, offsets, total_elem_size, vertex_array_shape, array_len, noindex, 0, laabb, bone_aabb); aabb.merge_with(laabb); - if (err2 != OK) { - ERR_EXPLAIN("Invalid blend shape array format for surface"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(err2 != OK, "Invalid blend shape array format for surface."); blend_shape_data.push_back(vertex_array_shape); } |