diff options
-rw-r--r-- | modules/gridmap/grid_map.cpp | 1 | ||||
-rw-r--r-- | scene/gui/tabs.cpp | 2 | ||||
-rw-r--r-- | scene/resources/gradient.cpp | 13 | ||||
-rw-r--r-- | scene/resources/tile_set.cpp | 35 |
4 files changed, 32 insertions, 19 deletions
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 3caa7b1d12..994a84fbc4 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -241,6 +241,7 @@ Vector3 GridMap::get_cell_size() const { void GridMap::set_octant_size(int p_size) { + ERR_FAIL_COND(p_size == 0); octant_size = p_size; _recreate_octant_data(); } diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index 36571cc878..7b0836cd28 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -892,6 +892,8 @@ void Tabs::ensure_tab_visible(int p_idx) { } Rect2 Tabs::get_tab_rect(int p_tab) const { + + ERR_FAIL_INDEX_V(p_tab, tabs.size(), Rect2()); return Rect2(tabs[p_tab].ofs_cache, 0, tabs[p_tab].size_cache, get_size().height); } diff --git a/scene/resources/gradient.cpp b/scene/resources/gradient.cpp index 99ce8ef821..1ff02c2f82 100644 --- a/scene/resources/gradient.cpp +++ b/scene/resources/gradient.cpp @@ -143,6 +143,8 @@ void Gradient::set_points(Vector<Gradient::Point> &p_points) { } void Gradient::set_offset(int pos, const float offset) { + + ERR_FAIL_COND(pos < 0); if (points.size() <= pos) points.resize(pos + 1); points.write[pos].offset = offset; @@ -151,12 +153,12 @@ void Gradient::set_offset(int pos, const float offset) { } float Gradient::get_offset(int pos) const { - if (points.size() && points.size() > pos) - return points[pos].offset; - return 0; //TODO: Maybe throw some error instead? + ERR_FAIL_INDEX_V(pos, points.size(), 0.0); + return points[pos].offset; } void Gradient::set_color(int pos, const Color &color) { + ERR_FAIL_COND(pos < 0); if (points.size() <= pos) { points.resize(pos + 1); is_sorted = false; @@ -166,9 +168,8 @@ void Gradient::set_color(int pos, const Color &color) { } Color Gradient::get_color(int pos) const { - if (points.size() && points.size() > pos) - return points[pos].color; - return Color(0, 0, 0, 1); //TODO: Maybe throw some error instead? + ERR_FAIL_INDEX_V(pos, points.size(), Color()); + return points[pos].color; } int Gradient::get_points_count() const { diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index d09fac47f0..f577a2e144 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -692,6 +692,8 @@ String TileSet::tile_get_name(int p_id) const { } void TileSet::tile_clear_shapes(int p_id) { + + ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].shapes_data.clear(); } @@ -711,13 +713,14 @@ void TileSet::tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transf int TileSet::tile_get_shape_count(int p_id) const { ERR_FAIL_COND_V(!tile_map.has(p_id), 0); - return tile_map[p_id].shapes_data.size(); } void TileSet::tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_shape) { ERR_FAIL_COND(!tile_map.has(p_id)); + ERR_FAIL_COND(p_shape_id < 0); + if (tile_map[p_id].shapes_data.size() <= p_shape_id) tile_map[p_id].shapes_data.resize(p_shape_id + 1); tile_map[p_id].shapes_data.write[p_shape_id].shape = p_shape; @@ -728,15 +731,16 @@ void TileSet::tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_sha Ref<Shape2D> TileSet::tile_get_shape(int p_id, int p_shape_id) const { ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<Shape2D>()); - if (tile_map[p_id].shapes_data.size() > p_shape_id) - return tile_map[p_id].shapes_data[p_shape_id].shape; + ERR_FAIL_INDEX_V(p_shape_id, tile_map[p_id].shapes_data.size(), Ref<Shape2D>()); - return Ref<Shape2D>(); + return tile_map[p_id].shapes_data[p_shape_id].shape; } void TileSet::tile_set_shape_transform(int p_id, int p_shape_id, const Transform2D &p_offset) { ERR_FAIL_COND(!tile_map.has(p_id)); + ERR_FAIL_INDEX(p_shape_id, tile_map[p_id].shapes_data.size()); + if (tile_map[p_id].shapes_data.size() <= p_shape_id) tile_map[p_id].shapes_data.resize(p_shape_id + 1); tile_map[p_id].shapes_data.write[p_shape_id].shape_transform = p_offset; @@ -746,10 +750,9 @@ void TileSet::tile_set_shape_transform(int p_id, int p_shape_id, const Transform Transform2D TileSet::tile_get_shape_transform(int p_id, int p_shape_id) const { ERR_FAIL_COND_V(!tile_map.has(p_id), Transform2D()); - if (tile_map[p_id].shapes_data.size() > p_shape_id) - return tile_map[p_id].shapes_data[p_shape_id].shape_transform; + ERR_FAIL_INDEX_V(p_shape_id, tile_map[p_id].shapes_data.size(), Transform2D()); - return Transform2D(); + return tile_map[p_id].shapes_data[p_shape_id].shape_transform; } void TileSet::tile_set_shape_offset(int p_id, int p_shape_id, const Vector2 &p_offset) { @@ -765,6 +768,8 @@ Vector2 TileSet::tile_get_shape_offset(int p_id, int p_shape_id) const { void TileSet::tile_set_shape_one_way(int p_id, int p_shape_id, const bool p_one_way) { ERR_FAIL_COND(!tile_map.has(p_id)); + ERR_FAIL_COND(p_shape_id < 0); + if (tile_map[p_id].shapes_data.size() <= p_shape_id) tile_map[p_id].shapes_data.resize(p_shape_id + 1); tile_map[p_id].shapes_data.write[p_shape_id].one_way_collision = p_one_way; @@ -774,14 +779,16 @@ void TileSet::tile_set_shape_one_way(int p_id, int p_shape_id, const bool p_one_ bool TileSet::tile_get_shape_one_way(int p_id, int p_shape_id) const { ERR_FAIL_COND_V(!tile_map.has(p_id), false); - if (tile_map[p_id].shapes_data.size() > p_shape_id) - return tile_map[p_id].shapes_data[p_shape_id].one_way_collision; + ERR_FAIL_INDEX_V(p_shape_id, tile_map[p_id].shapes_data.size(), false); - return false; + return tile_map[p_id].shapes_data[p_shape_id].one_way_collision; } void TileSet::tile_set_shape_one_way_margin(int p_id, int p_shape_id, float p_margin) { + ERR_FAIL_COND(!tile_map.has(p_id)); + ERR_FAIL_COND(p_shape_id < 0); + if (tile_map[p_id].shapes_data.size() <= p_shape_id) tile_map[p_id].shapes_data.resize(p_shape_id + 1); tile_map[p_id].shapes_data.write[p_shape_id].one_way_collision_margin = p_margin; @@ -789,11 +796,11 @@ void TileSet::tile_set_shape_one_way_margin(int p_id, int p_shape_id, float p_ma } float TileSet::tile_get_shape_one_way_margin(int p_id, int p_shape_id) const { + ERR_FAIL_COND_V(!tile_map.has(p_id), 0); - if (tile_map[p_id].shapes_data.size() > p_shape_id) - return tile_map[p_id].shapes_data[p_shape_id].one_way_collision_margin; + ERR_FAIL_INDEX_V(p_shape_id, tile_map[p_id].shapes_data.size(), 0.0); - return 0; + return tile_map[p_id].shapes_data[p_shape_id].one_way_collision_margin; } void TileSet::tile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder) { @@ -820,7 +827,9 @@ void TileSet::autotile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> } Ref<OccluderPolygon2D> TileSet::autotile_get_light_occluder(int p_id, const Vector2 &p_coord) const { + ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<OccluderPolygon2D>()); + if (!tile_map[p_id].autotile_data.occluder_map.has(p_coord)) { return Ref<OccluderPolygon2D>(); } else { |