axmolengine / axmol

Axmol Engine – A Multi-platform Engine for Desktop, XBOX (UWP) and Mobile games. (A fork of Cocos2d-x-4.0)
https://axmol.dev
MIT License
877 stars 194 forks source link

With the new resolution (g_designSize: 960, 640) I get this exception on cpp_test: void Sweep::EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangle, Point& point) { #1075

Closed aismann closed 1 year ago

aismann commented 1 year ago

latest

48 node::SpritePloygon -> after 7

image

halx99 commented 1 year ago

I revert design size: https://github.com/axmolengine/axmol/commit/56d4140628d2166c3ba93904539f8f4dc3c6cfcf

aismann commented 1 year ago

Should we not fix this bug?

halx99 commented 1 year ago

Can take a look does some tests of cpp-tests design for specific design-size

halx99 commented 1 year ago

@aismann This issue caused by clipper2, when I revert to clipper1, works well, can you take a look?

aismann commented 1 year ago

Yes.

aismann commented 1 year ago

@halx99 Please add pinned.

halx99 commented 1 year ago

Some hint log:

    /*
    * clipper1
    ##################### outPoints count: 5772, cost 250.085 (ms)
    ##################### outPoints count: 5772, cost 252.699 (ms)
    ##################### outPoints count: 5772, cost 251.789 (ms)
    ##################### outPoints count: 5772, cost 250.371 (ms)
    ##################### outPoints count: 5772, cost 250.287 (ms)

    * clipper2:
    * ##################### outPoints count: 5827, cost 43.250 (ms)
    */
halx99 commented 1 year ago

@aismann Caused by duplicate outPoints, remove duplicated points will solve this issue(notes: the outPoints generate by clipper1 no duplicates):

    struct point64_less
    {
        bool operator()(const Clipper2Lib::Point64* lhs, const Clipper2Lib::Point64* rhs) const
        {
           return lhs->x < rhs->x || (lhs->x == rhs->x && lhs->y < rhs->y);
        }
    };

    std::set<const Clipper2Lib::Point64*, point64_less> pointSets;
    for (auto&& p2 : out)
    {
        if (!p2->IsHole())
        {
            outPoints.reserve(outPoints.size() + p2->Polygon().size());
            for (auto&& so : p2->Polygon())
            {
                if(pointSets.emplace(&so).second)
                    outPoints.emplace_back(so.x / PRECISION, so.y / PRECISION);
            }
        }
        else
        {
            AXLOG("Clipper2 detect a hole!");
        }
    }
aismann commented 1 year ago

@halx99 Thanks. I have seen it too. But no time at the Moment

Edit: Clipper has: cl.StrictlySimple(true); Clipper2 not. For me its looks more as a "bug/Missing function" of Clipper2 or a wrong implementation on AutoPolygon::expand. I dont want add a "workaround" without ask the Clipper2 developer too. => I have to write an 'example' for the clipper2 issue stuff

halx99 commented 1 year ago

About duplicates outPoints, refer to

halx99 commented 1 year ago

@halx99 Thanks. I have seen it too. But no time at the Moment

Edit: Clipper has: cl.StrictlySimple(true); Clipper2 not. For me its looks more as a "bug/Missing function" of Clipper2 or a wrong implementation on AutoPolygon::expand. I dont want add a "workaround" without ask the Clipper2 developer too. => I have to write an 'example' for the clipper2 issue stuff

You can ask the clipper2 developer.

aismann commented 1 year ago

Maybe this "function" helps: (not tested) Clipper2Lib::SimplifyPath(out.Polygon(), epsilon, false);

If yes -> performance will be interesting

aismann commented 1 year ago

I have tested it and it looks very fast!

Changing also the tester: (0.5 => 1.0) auto pinfo = AutoPolygon::generatePolygon("Images/sprite_polygon_crash.png", Rect::ZERO, 1.0);

Can you send me the code snippet for this performance line too? * ##################### outPoints count: 5827, cost 43.250 (ms)

aismann commented 1 year ago

with

 Clipper2Lib::SimplifyPath(out.Polygon(), epsilon, false);
 auto pinfo  = AutoPolygon::generatePolygon("Images/sprite_polygon_crash.png", Rect::ZERO, 2.0);

it looks also "fine" and its very very fast (of course!) only 13419 vertices image

aismann commented 1 year ago

with epsilon 1.0: image

halx99 commented 1 year ago

##################### outPoints count: 5827, cost 43.250 (ms) it's the original clipper2 perf

halx99 commented 1 year ago

with

 Clipper2Lib::SimplifyPath(out.Polygon(), epsilon, false);
 auto pinfo  = AutoPolygon::generatePolygon("Images/sprite_polygon_crash.png", Rect::ZERO, 2.0);

it looks also "fine" and its very very fast (of course!) only 13419 vertices image

will test on my machine with your solution

halx99 commented 1 year ago

Notes: upstream: https://github.com/axmolengine/axmol/commit/0bb8c89ef350fa233b04850f9008337e68e4d5bc

#################### #outPoints count : 5813, cost 41.439(ms)
#################### #outPoints count : 5813, cost 42.136(ms)
#################### #outPoints count : 5813, cost 41.424(ms)
#################### #outPoints count : 5813, cost 41.933(ms)
#################### #outPoints count : 5813, cost 41.414(ms)
#################### #outPoints count : 5813, cost 41.721(ms)
halx99 commented 1 year ago

Clipper2Lib::SimplifyPath(out.Polygon(), epsilon, false);

Still crash with the code snippet:

std::vector<Vec2> outPoints;
    for (auto&& p2 : out)
    {
        if (!p2->IsHole())
        {

            Clipper2Lib::SimplifyPath(p2->Polygon(), epsilon, false);
            outPoints.reserve(outPoints.size() + p2->Polygon().size());
            for (auto&& so : p2->Polygon())
            {
                outPoints.emplace_back(so.x / PRECISION, so.y / PRECISION);
            }
        }
        else
        {
            AXLOG("Clipper2 detect a hole!");
        }
    }