Skip to content

Commit

Permalink
TileSet Editor: Check polygon size before indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga committed Jul 21, 2020
1 parent fa3ac7d commit 6f428f2
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions editor/plugins/tile_set_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,7 @@ void TileSetEditor::_set_edited_shape_points(const Vector<Vector2> &points) {
if (convex.is_valid()) {
undo_redo->add_do_method(convex.ptr(), "set_points", points);
undo_redo->add_undo_method(convex.ptr(), "set_points", _get_edited_shape_points());
} else if (concave.is_valid()) {
} else if (concave.is_valid() && points.size() > 1) {
PackedVector2Array segments;
for (int i = 0; i < points.size() - 1; i++) {
segments.push_back(points[i]);
Expand Down Expand Up @@ -2669,7 +2669,7 @@ void TileSetEditor::draw_polygon_shapes() {
workspace->draw_polygon(polygon, colors);

if (coord == edited_shape_coord || tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
if (!creating_shape) {
if (!creating_shape && polygon.size() > 1) {
for (int j = 0; j < polygon.size() - 1; j++) {
workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1);
}
Expand Down Expand Up @@ -2706,13 +2706,11 @@ void TileSetEditor::draw_polygon_shapes() {
}
workspace->draw_polygon(polygon, colors);

if (!creating_shape) {
if (polygon.size() > 1) {
for (int j = 0; j < polygon.size() - 1; j++) {
workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1);
}
workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1);
if (!creating_shape && polygon.size() > 1) {
for (int j = 0; j < polygon.size() - 1; j++) {
workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1);
}
workspace->draw_line(polygon[polygon.size() - 1], polygon[0], c_border, 1);
}
if (shape == edited_occlusion_shape) {
draw_handles = true;
Expand Down Expand Up @@ -2756,7 +2754,7 @@ void TileSetEditor::draw_polygon_shapes() {
workspace->draw_polygon(polygon, colors);

if (coord == edited_shape_coord) {
if (!creating_shape) {
if (!creating_shape && polygon.size() > 1) {
for (int j = 0; j < polygon.size() - 1; j++) {
workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1);
}
Expand Down Expand Up @@ -2796,7 +2794,7 @@ void TileSetEditor::draw_polygon_shapes() {
}
workspace->draw_polygon(polygon, colors);

if (!creating_shape) {
if (!creating_shape && polygon.size() > 1) {
for (int j = 0; j < polygon.size() - 1; j++) {
workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1);
}
Expand Down Expand Up @@ -2845,7 +2843,7 @@ void TileSetEditor::draw_polygon_shapes() {
workspace->draw_polygon(polygon, colors);

if (coord == edited_shape_coord) {
if (!creating_shape) {
if (!creating_shape && polygon.size() > 1) {
for (int j = 0; j < polygon.size() - 1; j++) {
workspace->draw_line(polygon[j], polygon[j + 1], c_border, 1);
}
Expand All @@ -2863,7 +2861,7 @@ void TileSetEditor::draw_polygon_shapes() {
}
}

if (creating_shape) {
if (creating_shape && current_shape.size() > 1) {
for (int j = 0; j < current_shape.size() - 1; j++) {
workspace->draw_line(current_shape[j], current_shape[j + 1], Color(0, 1, 1), 1);
}
Expand Down

0 comments on commit 6f428f2

Please sign in to comment.