Skip to content

Fix MSVC warning for potential mod by 0 (C4724) #106634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions editor/plugins/gizmos/collision_polygon_3d_gizmo_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ void CollisionPolygon3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
float depth = polygon->get_depth() * 0.5;

Vector<Vector3> lines;
for (int i = 0; i < points.size(); i++) {
int n = (i + 1) % points.size();
const int points_size = points.size();

for (int i = 0; i < points_size; i++) {
int n = (i + 1) % points_size;
lines.push_back(Vector3(points[i].x, points[i].y, depth));
lines.push_back(Vector3(points[n].x, points[n].y, depth));
lines.push_back(Vector3(points[i].x, points[i].y, -depth));
Expand All @@ -119,24 +121,25 @@ void CollisionPolygon3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
// Determine orientation of the 2D polygon's vertices to determine
// which direction to draw outer polygons.
float signed_area = 0.0f;
for (int i = 0; i < points.size(); i++) {
const int j = (i + 1) % points.size();
for (int i = 0; i < points_size; i++) {
const int j = (i + 1) % points_size;
signed_area += points[i].x * points[j].y - points[j].x * points[i].y;
}

// Generate triangles for the sides of the extruded polygon.
for (int i = 0; i < points.size(); i++) {
for (int i = 0; i < points_size; i++) {
verts.push_back(Vector3(points[i].x, points[i].y, depth));
verts.push_back(Vector3(points[i].x, points[i].y, -depth));

colors.push_back(collision_color);
colors.push_back(collision_color);
}

for (int i = 0; i < verts.size(); i += 2) {
const int j = (i + 1) % verts.size();
const int k = (i + 2) % verts.size();
const int l = (i + 3) % verts.size();
const int verts_size = verts.size();
for (int i = 0; i < verts_size; i += 2) {
const int j = (i + 1) % verts_size;
const int k = (i + 2) % verts_size;
const int l = (i + 3) % verts_size;

indices.push_back(i);
if (signed_area < 0) {
Expand Down Expand Up @@ -165,18 +168,19 @@ void CollisionPolygon3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Vector<Color> cap_colours_bottom;
Vector<int> cap_indices_bottom;

const int index_offset = verts.size();
const int index_offset = verts_size;

const Vector<Vector2> &convex = decomp[i];
const int convex_size = convex.size();

for (int j = 0; j < convex.size(); j++) {
for (int j = 0; j < convex_size; j++) {
cap_verts_bottom.push_back(Vector3(convex[j].x, convex[j].y, -depth));
cap_colours_bottom.push_back(collision_color);
}

if (convex.size() >= 3) {
for (int j = 1; j < convex.size(); j++) {
const int k = (j + 1) % convex.size();
if (convex_size >= 3) {
for (int j = 1; j < convex_size; j++) {
const int k = (j + 1) % convex_size;

cap_indices_bottom.push_back(index_offset + 0);
cap_indices_bottom.push_back(index_offset + j);
Expand All @@ -194,18 +198,19 @@ void CollisionPolygon3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Vector<Color> cap_colours_top;
Vector<int> cap_indices_top;

const int index_offset = verts.size();
const int index_offset = verts_size;

const Vector<Vector2> &convex = decomp[i];
const int convex_size = convex.size();

for (int j = 0; j < convex.size(); j++) {
for (int j = 0; j < convex_size; j++) {
cap_verts_top.push_back(Vector3(convex[j].x, convex[j].y, depth));
cap_colours_top.push_back(collision_color);
}

if (convex.size() >= 3) {
for (int j = 1; j < convex.size(); j++) {
const int k = (j + 1) % convex.size();
if (convex_size >= 3) {
for (int j = 1; j < convex_size; j++) {
const int k = (j + 1) % convex_size;

cap_indices_top.push_back(index_offset + k);
cap_indices_top.push_back(index_offset + j);
Expand Down