From 6cbaf7662f5ee3ca1d02c0ebc85854fceee057af Mon Sep 17 00:00:00 2001 From: qarmin Date: Sat, 20 Jul 2019 08:09:57 +0200 Subject: [PATCH] Changed some code showed in LGTM and Coverage --- core/image.cpp | 54 +++++++++---------- core/input_map.cpp | 2 +- core/io/resource_format_binary.cpp | 2 +- core/io/resource_saver.cpp | 1 - core/io/stream_peer.cpp | 4 +- core/math/bsp_tree.cpp | 4 +- core/math/expression.cpp | 6 +-- core/pool_allocator.cpp | 2 +- core/pool_vector.h | 4 +- core/string_name.cpp | 3 -- core/variant.cpp | 4 +- core/variant_call.cpp | 2 +- core/variant_op.cpp | 2 +- core/variant_parser.cpp | 2 - drivers/gles2/rasterizer_scene_gles2.cpp | 18 +++---- drivers/gles2/rasterizer_storage_gles2.cpp | 7 ++- drivers/gles3/rasterizer_scene_gles3.cpp | 15 ++---- drivers/gles3/rasterizer_storage_gles3.cpp | 9 ++-- editor/editor_node.cpp | 4 +- editor/editor_properties.cpp | 3 +- editor/editor_properties_array_dict.cpp | 5 -- editor/import/resource_importer_scene.cpp | 1 - editor/import/resource_importer_wav.cpp | 5 ++ editor/plugins/canvas_item_editor_plugin.cpp | 2 +- editor/plugins/material_editor_plugin.cpp | 3 -- editor/plugins/mesh_editor_plugin.cpp | 3 -- .../resource_preloader_editor_plugin.cpp | 3 -- editor/plugins/texture_editor_plugin.cpp | 3 -- .../plugins/texture_region_editor_plugin.cpp | 11 ++-- .../plugins/visual_shader_editor_plugin.cpp | 1 - editor/project_settings_editor.cpp | 2 - editor/property_editor.cpp | 3 +- editor/property_selector.cpp | 2 +- modules/gdscript/gdscript_editor.cpp | 2 - modules/gdscript/gdscript_parser.cpp | 2 - modules/gridmap/grid_map.cpp | 5 -- modules/theora/video_stream_theora.cpp | 1 - modules/visual_script/visual_script.cpp | 2 - .../visual_script/visual_script_editor.cpp | 1 - modules/visual_script/visual_script_nodes.cpp | 3 +- .../visual_script_property_selector.cpp | 2 +- platform/iphone/export/export.cpp | 3 +- scene/2d/cpu_particles_2d.cpp | 3 -- scene/3d/cpu_particles.cpp | 3 -- scene/3d/light.cpp | 3 -- scene/3d/sprite_3d.cpp | 2 +- scene/3d/visual_instance.cpp | 13 ----- scene/gui/base_button.cpp | 3 -- scene/gui/tree.cpp | 2 - scene/main/node.cpp | 2 +- scene/main/viewport.cpp | 2 +- scene/resources/animation.cpp | 17 ++---- scene/resources/resource_format_text.cpp | 4 -- servers/physics/shape_sw.cpp | 10 ---- .../physics_2d/collision_solver_2d_sat.cpp | 19 ++++--- 55 files changed, 94 insertions(+), 202 deletions(-) diff --git a/core/image.cpp b/core/image.cpp index a88395204af..10778eced65 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -240,27 +240,27 @@ int Image::get_format_block_size(Format p_format) { case FORMAT_RGTC_RG: { //bc5 case case FORMAT_DXT1: return 4; - } break; + } case FORMAT_PVRTC2: case FORMAT_PVRTC2A: { return 4; - } break; + } case FORMAT_PVRTC4A: case FORMAT_PVRTC4: { return 4; - } break; + } case FORMAT_ETC: { return 4; - } break; + } case FORMAT_BPTC_RGBA: case FORMAT_BPTC_RGBF: case FORMAT_BPTC_RGBFU: { return 4; - } break; + } case FORMAT_ETC2_R11: //etc2 case FORMAT_ETC2_R11S: //signed: NOT srgb. case FORMAT_ETC2_RG11: @@ -270,7 +270,7 @@ int Image::get_format_block_size(Format p_format) { case FORMAT_ETC2_RGB8A1: { return 4; - } break; + } default: { } } @@ -852,7 +852,7 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict static void _overlay(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, float p_alpha, uint32_t p_width, uint32_t p_height, uint32_t p_pixel_size) { - uint16_t alpha = CLAMP((uint16_t)(p_alpha * 256.0f), 0, 256); + uint16_t alpha = MIN((uint16_t)(p_alpha * 256.0f), 256); for (uint32_t i = 0; i < p_width * p_height * p_pixel_size; i++) { @@ -2421,38 +2421,36 @@ Color Image::get_pixel(int p_x, int p_y) const { case FORMAT_L8: { float l = ptr[ofs] / 255.0; return Color(l, l, l, 1); - } break; + } case FORMAT_LA8: { float l = ptr[ofs * 2 + 0] / 255.0; float a = ptr[ofs * 2 + 1] / 255.0; return Color(l, l, l, a); - } break; + } case FORMAT_R8: { float r = ptr[ofs] / 255.0; return Color(r, 0, 0, 1); - } break; + } case FORMAT_RG8: { float r = ptr[ofs * 2 + 0] / 255.0; float g = ptr[ofs * 2 + 1] / 255.0; return Color(r, g, 0, 1); - } break; + } case FORMAT_RGB8: { float r = ptr[ofs * 3 + 0] / 255.0; float g = ptr[ofs * 3 + 1] / 255.0; float b = ptr[ofs * 3 + 2] / 255.0; return Color(r, g, b, 1); - - } break; + } case FORMAT_RGBA8: { float r = ptr[ofs * 4 + 0] / 255.0; float g = ptr[ofs * 4 + 1] / 255.0; float b = ptr[ofs * 4 + 2] / 255.0; float a = ptr[ofs * 4 + 3] / 255.0; return Color(r, g, b, a); - - } break; + } case FORMAT_RGBA4444: { uint16_t u = ((uint16_t *)ptr)[ofs]; float r = (u & 0xF) / 15.0; @@ -2460,8 +2458,7 @@ Color Image::get_pixel(int p_x, int p_y) const { float b = ((u >> 8) & 0xF) / 15.0; float a = ((u >> 12) & 0xF) / 15.0; return Color(r, g, b, a); - - } break; + } case FORMAT_RGBA5551: { uint16_t u = ((uint16_t *)ptr)[ofs]; @@ -2470,25 +2467,25 @@ Color Image::get_pixel(int p_x, int p_y) const { float b = ((u >> 10) & 0x1F) / 15.0; float a = ((u >> 15) & 0x1) / 1.0; return Color(r, g, b, a); - } break; + } case FORMAT_RF: { float r = ((float *)ptr)[ofs]; return Color(r, 0, 0, 1); - } break; + } case FORMAT_RGF: { float r = ((float *)ptr)[ofs * 2 + 0]; float g = ((float *)ptr)[ofs * 2 + 1]; return Color(r, g, 0, 1); - } break; + } case FORMAT_RGBF: { float r = ((float *)ptr)[ofs * 3 + 0]; float g = ((float *)ptr)[ofs * 3 + 1]; float b = ((float *)ptr)[ofs * 3 + 2]; return Color(r, g, b, 1); - } break; + } case FORMAT_RGBAF: { float r = ((float *)ptr)[ofs * 4 + 0]; @@ -2496,25 +2493,25 @@ Color Image::get_pixel(int p_x, int p_y) const { float b = ((float *)ptr)[ofs * 4 + 2]; float a = ((float *)ptr)[ofs * 4 + 3]; return Color(r, g, b, a); - } break; + } case FORMAT_RH: { uint16_t r = ((uint16_t *)ptr)[ofs]; return Color(Math::half_to_float(r), 0, 0, 1); - } break; + } case FORMAT_RGH: { uint16_t r = ((uint16_t *)ptr)[ofs * 2 + 0]; uint16_t g = ((uint16_t *)ptr)[ofs * 2 + 1]; return Color(Math::half_to_float(r), Math::half_to_float(g), 0, 1); - } break; + } case FORMAT_RGBH: { uint16_t r = ((uint16_t *)ptr)[ofs * 3 + 0]; uint16_t g = ((uint16_t *)ptr)[ofs * 3 + 1]; uint16_t b = ((uint16_t *)ptr)[ofs * 3 + 2]; return Color(Math::half_to_float(r), Math::half_to_float(g), Math::half_to_float(b), 1); - } break; + } case FORMAT_RGBAH: { uint16_t r = ((uint16_t *)ptr)[ofs * 4 + 0]; @@ -2522,18 +2519,15 @@ Color Image::get_pixel(int p_x, int p_y) const { uint16_t b = ((uint16_t *)ptr)[ofs * 4 + 2]; uint16_t a = ((uint16_t *)ptr)[ofs * 4 + 3]; return Color(Math::half_to_float(r), Math::half_to_float(g), Math::half_to_float(b), Math::half_to_float(a)); - } break; + } case FORMAT_RGBE9995: { return Color::from_rgbe9995(((uint32_t *)ptr)[ofs]); - - } break; + } default: { ERR_EXPLAIN("Can't get_pixel() on compressed image, sorry."); ERR_FAIL_V(Color()); } } - - return Color(); } void Image::set_pixelv(const Point2 &p_dst, const Color &p_color) { diff --git a/core/input_map.cpp b/core/input_map.cpp index 04911787a85..165999f0811 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -202,7 +202,7 @@ bool InputMap::event_get_action_status(const Ref &p_event, const Str if (p_pressed != NULL) *p_pressed = input_event_action->is_pressed(); if (p_strength != NULL) - *p_strength = (*p_pressed) ? input_event_action->get_strength() : 0.0f; + *p_strength = (p_pressed != NULL && *p_pressed) ? input_event_action->get_strength() : 0.0f; return input_event_action->get_action() == p_action; } diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 861e34e415f..38bef2768ea 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -712,8 +712,8 @@ Error ResourceInteractiveLoaderBinary::poll() { if (!obj) { error = ERR_FILE_CORRUPT; ERR_EXPLAIN(local_path + ":Resource of unrecognized type in file: " + t); + ERR_FAIL_V(ERR_FILE_CORRUPT); } - ERR_FAIL_COND_V(!obj, ERR_FILE_CORRUPT); Resource *r = Object::cast_to(obj); if (!r) { diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 0cecca904d2..e2c1c3402ae 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -137,7 +137,6 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t save_callback(p_resource, p_path); return OK; - } else { } } diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index acf72dbba54..84b8554d54f 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -369,7 +369,9 @@ Variant StreamPeer::get_var(bool p_allow_objects) { ERR_FAIL_COND_V(err != OK, Variant()); Variant ret; - decode_variant(ret, var.ptr(), len, NULL, p_allow_objects); + err = decode_variant(ret, var.ptr(), len, NULL, p_allow_objects); + ERR_FAIL_COND_V(err != OK, Variant()); + return ret; } diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp index a12f9fee2e6..cfa698282e6 100644 --- a/core/math/bsp_tree.cpp +++ b/core/math/bsp_tree.cpp @@ -192,7 +192,7 @@ int BSP_Tree::get_points_inside(const Vector3 *p_points, int p_point_count) cons #ifdef DEBUG_ENABLED int plane_count = planes.size(); uint16_t plane = nodesptr[idx].plane; - ERR_FAIL_INDEX_V(plane, plane_count, false); + ERR_FAIL_UNSIGNED_INDEX_V(plane, plane_count, false); #endif idx = planesptr[nodesptr[idx].plane].is_point_over(point) ? nodes[idx].over : nodes[idx].under; @@ -258,7 +258,7 @@ bool BSP_Tree::point_is_inside(const Vector3 &p_point) const { #ifdef DEBUG_ENABLED int plane_count = planes.size(); uint16_t plane = nodesptr[idx].plane; - ERR_FAIL_INDEX_V(plane, plane_count, false); + ERR_FAIL_UNSIGNED_INDEX_V(plane, plane_count, false); #endif bool over = planesptr[nodesptr[idx].plane].is_point_over(p_point); diff --git a/core/math/expression.cpp b/core/math/expression.cpp index b52658e2cff..fb25fd9e0f4 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -793,17 +793,13 @@ Error Expression::_get_token(Token &r_token) { #define GET_CHAR() (str_ofs >= expression.length() ? 0 : expression[str_ofs++]) CharType cchar = GET_CHAR(); - if (cchar == 0) { - r_token.type = TK_EOF; - return OK; - } switch (cchar) { case 0: { r_token.type = TK_EOF; return OK; - } break; + }; case '{': { r_token.type = TK_CURLY_BRACKET_OPEN; diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp index 094352b5cc3..9b342ef9132 100644 --- a/core/pool_allocator.cpp +++ b/core/pool_allocator.cpp @@ -611,7 +611,7 @@ PoolAllocator::PoolAllocator(void *p_mem, int p_size, int p_align, bool p_needs_ PoolAllocator::PoolAllocator(int p_align, int p_size, bool p_needs_locking, int p_max_entries) { ERR_FAIL_COND(p_align < 1); - mem_ptr = Memory::alloc_static(p_size + p_align, "PoolAllocator()"); + mem_ptr = Memory::alloc_static(p_size + p_align, true); uint8_t *mem8 = (uint8_t *)mem_ptr; uint64_t ofs = (uint64_t)mem8; if (ofs % p_align) diff --git a/core/pool_vector.h b/core/pool_vector.h index 98a52c69381..3d28d86803b 100644 --- a/core/pool_vector.h +++ b/core/pool_vector.h @@ -458,7 +458,7 @@ public: bool is_locked() const { return alloc && alloc->lock > 0; } - inline const T operator[](int p_index) const; + inline T operator[](int p_index) const; Error resize(int p_size); @@ -502,7 +502,7 @@ void PoolVector::push_back(const T &p_val) { } template -const T PoolVector::operator[](int p_index) const { +T PoolVector::operator[](int p_index) const { CRASH_BAD_INDEX(p_index, size()); diff --git a/core/string_name.cpp b/core/string_name.cpp index 10b71ad3ac7..b1a8bfb8495 100644 --- a/core/string_name.cpp +++ b/core/string_name.cpp @@ -205,7 +205,6 @@ StringName::StringName(const char *p_name) { // exists lock->unlock(); return; - } else { } } @@ -253,7 +252,6 @@ StringName::StringName(const StaticCString &p_static_string) { // exists lock->unlock(); return; - } else { } } @@ -301,7 +299,6 @@ StringName::StringName(const String &p_name) { // exists lock->unlock(); return; - } else { } } diff --git a/core/variant.cpp b/core/variant.cpp index fe9623d068c..1574af52390 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -1834,8 +1834,6 @@ inline DA _convert_array_from_variant(const Variant &p_variant) { return DA(); } } - - return DA(); } Variant::operator Array() const { @@ -2299,7 +2297,7 @@ Variant::Variant(const Object *p_object) { Variant::Variant(const Dictionary &p_dictionary) { type = DICTIONARY; - memnew_placement(_data._mem, (Dictionary)(p_dictionary)); + memnew_placement(_data._mem, Dictionary(p_dictionary)); } Variant::Variant(const Array &p_array) { diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 3fdd18a6308..b637e745af0 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -70,7 +70,7 @@ struct _VariantCall { for (int i = 0; i < arg_count; i++) { - if (!tptr[i] || tptr[i] == p_args[i]->type) + if (tptr[i] == Variant::NIL || tptr[i] == p_args[i]->type) continue; // all good if (!Variant::can_convert(p_args[i]->type, tptr[i])) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; diff --git a/core/variant_op.cpp b/core/variant_op.cpp index d677c7776a6..ea9e29e7443 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -2613,7 +2613,7 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (r_valid) { *r_valid = false; } - return "Attempted get on stray pointer."; + return true; // Attempted get on stray pointer. } } #endif diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index d5513bc2d7a..07212ec6691 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -1537,8 +1537,6 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r Token token; get_token(p_stream, token, line, r_err_str); Error err = parse_value(token, r_value, p_stream, line, r_err_str, p_res_parser); - if (err) { - } return err; } } else if (c == '\n') { diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp index ea29af7d9ee..a380e4047cd 100644 --- a/drivers/gles2/rasterizer_scene_gles2.cpp +++ b/drivers/gles2/rasterizer_scene_gles2.cpp @@ -880,7 +880,11 @@ RID RasterizerSceneGLES2::light_instance_create(RID p_light) { light_instance->light_index = 0xFFFF; - ERR_FAIL_COND_V(!light_instance->light_ptr, RID()); + if (!light_instance->light_ptr) { + memdelete(light_instance); + ERR_EXPLAIN("Condition ' !light_instance->light_ptr ' is true."); + ERR_FAIL_V(RID()); + } light_instance->self = light_instance_owner.make_rid(light_instance); @@ -1963,9 +1967,7 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado width /= 2; height /= 2; - if (k == 0) { - - } else if (k == 1) { + if (k == 1) { x += width; } else if (k == 2) { y += height; @@ -1978,9 +1980,7 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado height /= 2; - if (k == 0) { - - } else { + if (k != 0) { y += height; } } @@ -3171,9 +3171,7 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_ width /= 2; height /= 2; - if (p_pass == 0) { - - } else if (p_pass == 1) { + if (p_pass == 1) { x += width; } else if (p_pass == 2) { y += height; diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index c591db4f3d6..a0188da4f61 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -3976,20 +3976,19 @@ AABB RasterizerStorageGLES2::light_get_aabb(RID p_light) const { float len = light->param[VS::LIGHT_PARAM_RANGE]; float size = Math::tan(Math::deg2rad(light->param[VS::LIGHT_PARAM_SPOT_ANGLE])) * len; return AABB(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len)); - } break; + }; case VS::LIGHT_OMNI: { float r = light->param[VS::LIGHT_PARAM_RANGE]; return AABB(-Vector3(r, r, r), Vector3(r, r, r) * 2); - } break; + }; case VS::LIGHT_DIRECTIONAL: { return AABB(); - } break; + }; } ERR_FAIL_V(AABB()); - return AABB(); } /* PROBE API */ diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index fb3d154a7a7..812e3711c5a 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -1008,7 +1008,8 @@ RID RasterizerSceneGLES3::light_instance_create(RID p_light) { if (!light_instance->light_ptr) { memdelete(light_instance); - ERR_FAIL_COND_V(!light_instance->light_ptr, RID()); + ERR_EXPLAIN("Condition ' !light_instance->light_ptr ' is true."); + ERR_FAIL_V(RID()); } light_instance->self = light_instance_owner.make_rid(light_instance); @@ -2763,9 +2764,7 @@ void RasterizerSceneGLES3::_setup_directional_light(int p_index, const Transform width /= 2; height /= 2; - if (j == 0) { - - } else if (j == 1) { + if (j == 1) { x += width; } else if (j == 2) { y += height; @@ -2778,9 +2777,7 @@ void RasterizerSceneGLES3::_setup_directional_light(int p_index, const Transform height /= 2; - if (j == 0) { - - } else { + if (j != 0) { y += height; } } @@ -4741,9 +4738,7 @@ void RasterizerSceneGLES3::render_shadow(RID p_light, RID p_shadow_atlas, int p_ width /= 2; height /= 2; - if (p_pass == 0) { - - } else if (p_pass == 1) { + if (p_pass == 1) { x += width; } else if (p_pass == 2) { y += height; diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 994ed25f013..57b4c198ebf 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -5471,22 +5471,19 @@ AABB RasterizerStorageGLES3::light_get_aabb(RID p_light) const { float len = light->param[VS::LIGHT_PARAM_RANGE]; float size = Math::tan(Math::deg2rad(light->param[VS::LIGHT_PARAM_SPOT_ANGLE])) * len; return AABB(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len)); - } break; + }; case VS::LIGHT_OMNI: { float r = light->param[VS::LIGHT_PARAM_RANGE]; return AABB(-Vector3(r, r, r), Vector3(r, r, r) * 2); - } break; + }; case VS::LIGHT_DIRECTIONAL: { return AABB(); - } break; - default: { - } + }; } ERR_FAIL_V(AABB()); - return AABB(); } /* PROBE API */ diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 3431930b8bd..8d533acd8b6 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -834,7 +834,7 @@ void EditorNode::_get_scene_metadata(const String &p_file) { for (List::Element *E = esl.front(); E; E = E->next()) { Variant st = cf->get_value("editor_states", E->get()); - if (st.get_type()) { + if (st.get_type() != Variant::NIL) { md[E->get()] = st; } } @@ -2543,8 +2543,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { restart_editor(); } break; default: { - if (p_option >= IMPORT_PLUGIN_BASE) { - } } } } diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index a8ef563368c..0cb13212448 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -389,7 +389,7 @@ void EditorPropertyMember::_property_select() { type = Variant::Type(i); } } - if (type) + if (type != Variant::NIL) selector->select_method_from_basic_type(type, current); } else if (hint == MEMBER_METHOD_OF_BASE_TYPE) { @@ -2412,7 +2412,6 @@ void EditorPropertyResource::_update_menu_items() { menu->add_separator(); menu->add_item(TTR("Show in FileSystem"), OBJ_MENU_SHOW_IN_FILE_SYSTEM); } - } else { } RES cb = EditorSettings::get_singleton()->get_resource_clipboard(); diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 347699c6324..203136a3f84 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -414,8 +414,6 @@ void EditorPropertyArray::_remove_pressed(int p_index) { } void EditorPropertyArray::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - } } void EditorPropertyArray::_edit_pressed() { @@ -968,9 +966,6 @@ void EditorPropertyDictionary::_object_id_selected(const String &p_property, Obj } void EditorPropertyDictionary::_notification(int p_what) { - - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - } } void EditorPropertyDictionary::_edit_pressed() { diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index a8197ec2a22..53b67c46b0c 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -893,7 +893,6 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { keep.insert(F->get()); } _filter_anim_tracks(anim->get_animation(name), keep); - } else { } } } diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index e728dbac310..d267b29224b 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -206,6 +206,11 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s frames = chunksize; + if (format_channels == 0) { + file->close(); + memdelete(file); + ERR_FAIL_COND_V(format_channels == 0, ERR_INVALID_DATA); + } frames /= format_channels; frames /= (format_bits >> 3); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 1f601e64fa9..7341d583764 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1406,7 +1406,7 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref &p_event) { for (int i = 0; i < 4; i++) { anchor_pos[i] = (transform * control->get_global_transform_with_canvas()).xform(_anchor_to_position(control, anchor_pos[i])); anchor_rects[i] = Rect2(anchor_pos[i], anchor_handle->get_size()); - anchor_rects[i].position -= anchor_handle->get_size() * Vector2(i == 0 || i == 3, i <= 1); + anchor_rects[i].position -= anchor_handle->get_size() * Vector2(float(i == 0 || i == 3), float(i <= 1)); } DragType dragger[] = { diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index ebacccb03c2..e125c18ef19 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -34,9 +34,6 @@ void MaterialEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_PHYSICS_PROCESS) { - } - if (p_what == NOTIFICATION_READY) { //get_scene()->connect("node_removed",this,"_node_removed"); diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp index 6203035e259..442110cc84f 100644 --- a/editor/plugins/mesh_editor_plugin.cpp +++ b/editor/plugins/mesh_editor_plugin.cpp @@ -48,9 +48,6 @@ void MeshEditor::_gui_input(Ref p_event) { void MeshEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_PHYSICS_PROCESS) { - } - if (p_what == NOTIFICATION_READY) { //get_scene()->connect("node_removed",this,"_node_removed"); diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index b8d95efd491..620bf284159 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -39,9 +39,6 @@ void ResourcePreloaderEditor::_gui_input(Ref p_event) { void ResourcePreloaderEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_PHYSICS_PROCESS) { - } - if (p_what == NOTIFICATION_ENTER_TREE) { load->set_icon(get_icon("Folder", "EditorIcons")); } diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index 0aa4a7662c1..6d71c56eada 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -39,9 +39,6 @@ void TextureEditor::_gui_input(Ref p_event) { void TextureEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_PHYSICS_PROCESS) { - } - if (p_what == NOTIFICATION_READY) { //get_scene()->connect("node_removed",this,"_node_removed"); diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 8f58fbd6aba..2d872c1a7f1 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -193,7 +193,7 @@ void TextureRegionEditor::_region_draw() { updating_scroll = false; if (node_ninepatch || obj_styleBox.is_valid()) { - float margins[4]; + float margins[4] = { 0 }; if (node_ninepatch) { margins[0] = node_ninepatch->get_patch_margin(MARGIN_TOP); margins[1] = node_ninepatch->get_patch_margin(MARGIN_BOTTOM); @@ -204,12 +204,8 @@ void TextureRegionEditor::_region_draw() { margins[1] = obj_styleBox->get_margin_size(MARGIN_BOTTOM); margins[2] = obj_styleBox->get_margin_size(MARGIN_LEFT); margins[3] = obj_styleBox->get_margin_size(MARGIN_RIGHT); - } else { - margins[0] = 0; - margins[1] = 0; - margins[2] = 0; - margins[3] = 0; } + Vector2 pos[4] = { mtx.basis_xform(Vector2(0, margins[0])) + Vector2(0, endpoints[0].y - draw_ofs.y * draw_zoom), -mtx.basis_xform(Vector2(0, margins[1])) + Vector2(0, endpoints[2].y - draw_ofs.y * draw_zoom), @@ -248,7 +244,7 @@ void TextureRegionEditor::_region_input(const Ref &p_input) { if (mb->is_pressed()) { if (node_ninepatch || obj_styleBox.is_valid()) { edited_margin = -1; - float margins[4]; + float margins[4] = { 0 }; if (node_ninepatch) { margins[0] = node_ninepatch->get_patch_margin(MARGIN_TOP); margins[1] = node_ninepatch->get_patch_margin(MARGIN_BOTTOM); @@ -260,6 +256,7 @@ void TextureRegionEditor::_region_input(const Ref &p_input) { margins[2] = obj_styleBox->get_margin_size(MARGIN_LEFT); margins[3] = obj_styleBox->get_margin_size(MARGIN_RIGHT); } + Vector2 pos[4] = { mtx.basis_xform(rect.position + Vector2(0, margins[0])) - draw_ofs * draw_zoom, mtx.basis_xform(rect.position + rect.size - Vector2(0, margins[1])) - draw_ofs * draw_zoom, diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 7ecceaed1dd..aad30085d76 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -1497,7 +1497,6 @@ void VisualShaderEditor::_notification(int p_what) { if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree()) _update_graph(); - } else if (p_what == NOTIFICATION_PROCESS) { } } diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 001846604c1..eb0b386febe 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -965,8 +965,6 @@ void ProjectSettingsEditor::_action_add() { while (r->get_next()) r = r->get_next(); - if (!r) - return; r->select(0); input_editor->ensure_cursor_is_visible(); action_add_error->hide(); diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 82d974cae31..899343c0f8d 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -614,7 +614,7 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: type = Variant::Type(i); } } - if (type) + if (type != Variant::NIL) property_select->select_method_from_basic_type(type, v); updating = false; return false; @@ -971,7 +971,6 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: menu->add_separator(); menu->add_item(TTR("Show in FileSystem"), OBJ_MENU_SHOW_IN_FILE_SYSTEM); } - } else { } RES cb = EditorSettings::get_singleton()->get_resource_clipboard(); diff --git a/editor/property_selector.cpp b/editor/property_selector.cpp index 813e24bd61f..3bc93c3900c 100644 --- a/editor/property_selector.cpp +++ b/editor/property_selector.cpp @@ -337,7 +337,7 @@ void PropertySelector::_item_selected() { String name = item->get_metadata(0); String class_type; - if (type) { + if (type != Variant::NIL) { class_type = Variant::get_type_name(type); } else { diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 78a1bfc99bc..f048010deaf 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -382,8 +382,6 @@ void GDScriptLanguage::debug_get_globals(List *p_globals, List String GDScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { - if (_debug_parse_err_line >= 0) - return ""; return ""; } diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 80da606967e..843162dcef3 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -1766,8 +1766,6 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to cn->value = v; cn->datatype = _type_from_variant(v); return cn; - - } else if (op->arguments[0]->type == Node::TYPE_BUILT_IN_FUNCTION && last_not_constant == 0) { } return op; //don't reduce yet diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 994a84fbc4c..bdecbbdbad6 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -481,11 +481,6 @@ bool GridMap::_octant_update(const OctantKey &p_key) { Transform xform; - if (clip && ((clip_above && cellpos[clip_axis] > clip_floor) || (!clip_above && cellpos[clip_axis] < clip_floor))) { - - } else { - } - xform.basis.set_orthogonal_index(c.rot); xform.set_origin(cellpos * cell_size + ofs); xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale)); diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index ae542713ea6..6a1b4633057 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -499,7 +499,6 @@ void VideoStreamPlaybackTheora::update(float p_delta) { /*If we are too slow, reduce the pp level.*/ pp_inc = pp_level > 0 ? -1 : 0; } - } else { } } else { diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index b816e379368..4425565afab 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -2629,8 +2629,6 @@ void VisualScriptLanguage::debug_get_globals(List *p_locals, List= 0) - return ""; return ""; } diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 31d5e4665a5..603c5a7f3cb 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -3670,7 +3670,6 @@ VisualScriptEditor::VisualScriptEditor() { new_virtual_method_select = memnew(VisualScriptPropertySelector); add_child(new_virtual_method_select); new_virtual_method_select->connect("selected", this, "_selected_new_virtual_method"); - new_virtual_method_select->get_cancel(); member_popup = memnew(PopupMenu); add_child(member_popup); diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 1b0e41b2ded..3b0210597bc 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -197,7 +197,6 @@ String VisualScriptFunction::get_output_sequence_port_text(int p_port) const { PropertyInfo VisualScriptFunction::get_input_value_port_info(int p_idx) const { ERR_FAIL_V(PropertyInfo()); - return PropertyInfo(); } PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const { @@ -418,7 +417,7 @@ PropertyInfo VisualScriptOperator::get_input_value_port_info(int p_idx) const { { Variant::NIL, Variant::NIL } //OP_IN, }; - ERR_FAIL_INDEX_V(p_idx, Variant::OP_MAX, PropertyInfo()); + ERR_FAIL_INDEX_V(p_idx, 2, PropertyInfo()); PropertyInfo pinfo; pinfo.name = p_idx == 0 ? "A" : "B"; diff --git a/modules/visual_script/visual_script_property_selector.cpp b/modules/visual_script/visual_script_property_selector.cpp index 1e7ed3019c7..41828f040e2 100644 --- a/modules/visual_script/visual_script_property_selector.cpp +++ b/modules/visual_script/visual_script_property_selector.cpp @@ -405,7 +405,7 @@ void VisualScriptPropertySelector::_item_selected() { String name = item->get_metadata(0); String class_type; - if (type) { + if (type != Variant::NIL) { class_type = Variant::get_type_name(type); } else { diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp index 85a45d62f8e..a179b36bd51 100644 --- a/platform/iphone/export/export.cpp +++ b/platform/iphone/export/export.cpp @@ -768,7 +768,8 @@ Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir DirAccess *da = DirAccess::create_for_path(asset); if (!da) { memdelete(filesystem_da); - ERR_FAIL_COND_V(!da, ERR_CANT_CREATE); + ERR_EXPLAIN("Can't create directory: " + asset); + ERR_FAIL_V(ERR_CANT_CREATE); } bool file_exists = da->file_exists(asset); bool dir_exists = da->dir_exists(asset); diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index 591933d9728..ab54cef5084 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -980,9 +980,6 @@ void CPUParticles2D::_notification(int p_what) { _set_redraw(false); } - if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) { - } - if (p_what == NOTIFICATION_DRAW) { if (!redraw) return; // don't add to render list diff --git a/scene/3d/cpu_particles.cpp b/scene/3d/cpu_particles.cpp index 86b407b9e60..dd64ffe9343 100644 --- a/scene/3d/cpu_particles.cpp +++ b/scene/3d/cpu_particles.cpp @@ -1059,9 +1059,6 @@ void CPUParticles::_notification(int p_what) { _set_redraw(false); } - if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) { - } - if (p_what == NOTIFICATION_INTERNAL_PROCESS) { if (particles.size() == 0 || !is_visible_in_tree()) { diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index 4ef945ab8db..73d3ab50e33 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -200,9 +200,6 @@ void Light::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { _update_visibility(); } - - if (p_what == NOTIFICATION_EXIT_TREE) { - } } void Light::set_editor_only(bool p_editor_only) { diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index 67c79d8b5a2..2c315790acd 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -558,7 +558,7 @@ Rect2 Sprite3D::get_region_rect() const { void Sprite3D::set_frame(int p_frame) { - ERR_FAIL_INDEX(p_frame, vframes * hframes); + ERR_FAIL_INDEX(p_frame, int64_t(vframes) * hframes); if (frame != p_frame) diff --git a/scene/3d/visual_instance.cpp b/scene/3d/visual_instance.cpp index 5141c848037..d1de0c56a78 100644 --- a/scene/3d/visual_instance.cpp +++ b/scene/3d/visual_instance.cpp @@ -215,17 +215,6 @@ float GeometryInstance::get_lod_max_hysteresis() const { } void GeometryInstance::_notification(int p_what) { - - if (p_what == NOTIFICATION_ENTER_WORLD) { - - if (flags[FLAG_USE_BAKED_LIGHT]) { - } - - } else if (p_what == NOTIFICATION_EXIT_WORLD) { - - if (flags[FLAG_USE_BAKED_LIGHT]) { - } - } } void GeometryInstance::set_flag(Flags p_flag, bool p_value) { @@ -236,8 +225,6 @@ void GeometryInstance::set_flag(Flags p_flag, bool p_value) { flags[p_flag] = p_value; VS::get_singleton()->instance_geometry_set_flag(get_instance(), (VS::InstanceFlags)p_flag, p_value); - if (p_flag == FLAG_USE_BAKED_LIGHT) { - } } bool GeometryInstance::get_flag(Flags p_flag) const { diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 52fcea2a71e..4f71481280c 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -115,9 +115,6 @@ void BaseButton::_notification(int p_what) { } } - if (p_what == NOTIFICATION_ENTER_TREE) { - } - if (p_what == NOTIFICATION_EXIT_TREE || (p_what == NOTIFICATION_VISIBILITY_CHANGED && !is_visible_in_tree())) { if (!toggle_mode) { diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 4005505830a..814100afdc4 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2921,8 +2921,6 @@ void Tree::_notification(int p_what) { drag_touching = false; drag_touching_deaccel = false; } - - } else { } } diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 06d6f0871cc..caa0da5d1f6 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -210,7 +210,7 @@ void Node::_propagate_enter_tree() { } data.viewport = Object::cast_to(this); - if (!data.viewport) + if (!data.viewport && data.parent) data.viewport = data.parent->data.viewport; data.inside_tree = true; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index d147d43f506..9466b7c5c1e 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -581,7 +581,7 @@ void Viewport::_notification(int p_what) { if (physics_object_capture != 0) { CollisionObject *co = Object::cast_to(ObjectDB::get_instance(physics_object_capture)); - if (co) { + if (co && camera) { _collision_object_input_event(co, camera, ev, Vector3(), Vector3(), 0); captured = true; if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) { diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 64051fe304a..8c8552ac54a 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -1667,8 +1667,7 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a Vector2 pb = p_post_b; return a.cubic_interpolate(b, pa, pb, p_c); - - } break; + } case Variant::RECT2: { Rect2 a = p_a; @@ -1679,8 +1678,7 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a return Rect2( a.position.cubic_interpolate(b.position, pa.position, pb.position, p_c), a.size.cubic_interpolate(b.size, pa.size, pb.size, p_c)); - - } break; + } case Variant::VECTOR3: { Vector3 a = p_a; @@ -1689,8 +1687,7 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a Vector3 pb = p_post_b; return a.cubic_interpolate(b, pa, pb, p_c); - - } break; + } case Variant::QUAT: { Quat a = p_a; @@ -1699,8 +1696,7 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a Quat pb = p_post_b; return a.cubic_slerp(b, pa, pb, p_c); - - } break; + } case Variant::AABB: { AABB a = p_a; @@ -1711,14 +1707,12 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a return AABB( a.position.cubic_interpolate(b.position, pa.position, pb.position, p_c), a.size.cubic_interpolate(b.size, pa.size, pb.size, p_c)); - } break; + } default: { return _interpolate(p_a, p_b, p_c); } } - - return Variant(); } float Animation::_cubic_interpolate(const float &p_pre_a, const float &p_a, const float &p_b, const float &p_post_b, float p_c) const { @@ -3028,7 +3022,6 @@ bool Animation::_transform_track_optimize_key(const TKey &t0, cons //this could be done as a second pass and would be //able to optimize more erase = false; - } else { } } } diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index 12bf007bb15..6212066c3c7 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -1371,8 +1371,6 @@ String ResourceFormatSaverTextInstance::_write_resource(const RES &res) { //internal resource } } - - return "null"; } void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant, bool p_main) { @@ -1514,8 +1512,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r } } - ERR_FAIL_COND_V(err != OK, err); - { String title = packed_scene.is_valid() ? "[gd_scene " : "[gd_resource "; if (packed_scene.is_null()) diff --git a/servers/physics/shape_sw.cpp b/servers/physics/shape_sw.cpp index 8a52f297299..f01caefdce3 100644 --- a/servers/physics/shape_sw.cpp +++ b/servers/physics/shape_sw.cpp @@ -543,16 +543,6 @@ void CapsuleShapeSW::project_range(const Vector3 &p_normal, const Transform &p_t r_max = p_normal.dot(p_transform.xform(n)); r_min = p_normal.dot(p_transform.xform(-n)); - return; - - n = p_transform.basis.xform(n); - - real_t distance = p_normal.dot(p_transform.origin); - real_t length = Math::abs(p_normal.dot(n)); - r_min = distance - length; - r_max = distance + length; - - ERR_FAIL_COND(r_max < r_min); } Vector3 CapsuleShapeSW::get_support(const Vector3 &p_normal) const { diff --git a/servers/physics_2d/collision_solver_2d_sat.cpp b/servers/physics_2d/collision_solver_2d_sat.cpp index f4bff663893..9d75f71ff08 100644 --- a/servers/physics_2d/collision_solver_2d_sat.cpp +++ b/servers/physics_2d/collision_solver_2d_sat.cpp @@ -313,10 +313,12 @@ public: if (best_axis == Vector2(0.0, 0.0)) return; - callback->collided = true; + if (callback) { + callback->collided = true; - if (!callback->callback) - return; //only collide, no callback + if (!callback->callback) + return; //only collide, no callback + } static const int max_supports = 2; Vector2 supports_A[max_supports]; @@ -354,12 +356,13 @@ public: supports_B[i] += best_axis * margin_B; } } + if (callback) { + callback->normal = best_axis; + _generate_contacts_from_supports(supports_A, support_count_A, supports_B, support_count_B, callback); - callback->normal = best_axis; - _generate_contacts_from_supports(supports_A, support_count_A, supports_B, support_count_B, callback); - - if (callback && callback->sep_axis && *callback->sep_axis != Vector2()) - *callback->sep_axis = Vector2(); //invalidate previous axis (no test) + if (callback->sep_axis && *callback->sep_axis != Vector2()) + *callback->sep_axis = Vector2(); //invalidate previous axis (no test) + } } _FORCE_INLINE_ SeparatorAxisTest2D(const ShapeA *p_shape_A, const Transform2D &p_transform_a, const ShapeB *p_shape_B, const Transform2D &p_transform_b, _CollectorCallback2D *p_collector, const Vector2 &p_motion_A = Vector2(), const Vector2 &p_motion_B = Vector2(), real_t p_margin_A = 0, real_t p_margin_B = 0) {