Skip to content
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

Quickhull - reduce warning spam and make hideable #51469

Merged
merged 1 commit into from
Aug 10, 2021
Merged
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
11 changes: 10 additions & 1 deletion core/math/quick_hull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
bool warning_f = false;
bool warning_o_equal_e = false;
bool warning_o = false;
bool warning_not_f2 = false;

for (List<Geometry::MeshData::Face>::Element *E = ret_faces.front(); E; E = E->next()) {
Geometry::MeshData::Face &f = E->get();
Expand Down Expand Up @@ -413,7 +414,12 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
Edge e2(idx, idxn);

Map<Edge, RetFaceConnect>::Element *F2 = ret_edges.find(e2);
ERR_CONTINUE(!F2);

if (unlikely(!F2)) {
warning_not_f2 = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use WARN_PRINT_ONCE() here instead of using booleans to defer it?

Copy link
Member Author

@lawnjelly lawnjelly Aug 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can easily change these to WARN_PRINT_ONCEs within the if statements.

This is just me, my reflex action is to write less branches 😁 . But in this case readability is probably the most important factor.

Copy link
Member Author

@lawnjelly lawnjelly Aug 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah no on second thoughts, it would involve 3 if statements because of the _flag_warnings parameter. So it may be better how it currently is, otherwise the logic in the hot loop could become harder to follow in terms of readability...

I.e. it would end up being:

if (unlikely(!F2))
{
    if (_flag_warnings)
    {
        WARN_PRINT_ONCE etc
    }
    continue;
}

I don't know which is preferred. I'd still slightly come out with the WARN_PRINTs separate as slightly better, but either is fine, I can change it, just let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All that logic is quite awkward IMO.

Errors and warnings should point at things that are either:

  • Engine bugs that we need to fix.
  • User mistakes where they pass invalid input.

If it's neither of those and those are benign cases which are not meant to call the user's attention, they should just be replaced by silent continue. If they are signs that the user or the engine is using bogus data, that's something we should fix.

continue;
}

//change faceconnect, point to this face instead
if (F2->get().left == O) {
F2->get().left = E;
Expand Down Expand Up @@ -453,6 +459,9 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
if (warning_o) {
WARN_PRINT("QuickHull : O == nullptr");
}
if (warning_not_f2) {
WARN_PRINT("QuickHull : !F2");
}
}

//fill mesh
Expand Down