Skip to content

Fix polygon trying to solve center with fewer than 3 vertices. - #1429

Open
GeneralProtectionFault wants to merge 1 commit into
Redot-Engine:masterfrom
GeneralProtectionFault:poly_fix
Open

GeneralProtectionFault wants to merge 1 commit into
Redot-Engine:masterfrom
GeneralProtectionFault:poly_fix

Conversation

@GeneralProtectionFault

@GeneralProtectionFault GeneralProtectionFault commented Sep 19, 2026

Copy link
Copy Markdown
Member

When adding a CollisionPolygon2D, the Output would spam:
ERROR: core/math/geometry_2d.cpp:110 - Convex decomposing failed!

This would spam on mouse drag, etc... as well until there was an actual "polygon."
This just adds a guard to the _get_geometric_center() function which bails out if there are fewer than 3 vertices (and thus no polygon yet).

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of degenerate 2D polygons in the editor.
    • Prevented potential errors when calculating the geometric center of polygons with fewer than three vertices.
    • Returns a stable default position when no valid polygon geometry is available.

@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: Redot-Engine/redot-engine/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 8e762408-3c38-4e95-b25f-07114029935b

📥 Commits

Reviewing files that changed from the base of the PR and between 2ab24bc and 49d0fdf.

📒 Files selected for processing (1)
  • editor/scene/2d/abstract_polygon_2d_editor.cpp

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Walkthrough

_get_geometric_center() now skips polygons with fewer than three vertices and returns Vector2() when convex decomposition produces no sub-polygons.

Changes

Polygon center calculation

Layer / File(s) Summary
Validate polygon center inputs
editor/scene/2d/abstract_polygon_2d_editor.cpp
The calculation skips polygons with fewer than three vertices. It returns Vector2() when no sub-polygons were accumulated, preventing division by zero.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: arctis-fireblight, davetheeggman

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: preventing geometric center calculation for polygons with fewer than three vertices. It is concise and related to the pull request objectives, although the…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Open

Development

Successfully merging this pull request may close these issues.

1 participant