diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/curve.cpp | 40 | ||||
-rw-r--r-- | scene/resources/dynamic_font.cpp | 13 | ||||
-rw-r--r-- | scene/resources/font.cpp | 10 | ||||
-rw-r--r-- | scene/resources/material.cpp | 5 | ||||
-rw-r--r-- | scene/resources/mesh.cpp | 23 | ||||
-rw-r--r-- | scene/resources/packed_scene.cpp | 13 | ||||
-rw-r--r-- | scene/resources/resource_format_text.cpp | 3 | ||||
-rw-r--r-- | scene/resources/text_file.cpp | 5 | ||||
-rw-r--r-- | scene/resources/texture.cpp | 6 | ||||
-rw-r--r-- | scene/resources/tile_set.cpp | 3 | ||||
-rw-r--r-- | scene/resources/visual_shader.cpp | 6 |
11 files changed, 30 insertions, 97 deletions
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()) { |