Search Unity

PolygonCollider2D stuck randomly, internal bug?

Discussion in 'Physics' started by iileychen, Apr 26, 2017.

  1. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    109
    I encounter a strange issue that:
    I will regenerate the path points, and call PolygonCollider2D.SetPath() for my complex shapes.

    Most time it works well, but sometimes, the Unity stuck with no response, I debug it with VS Studio and get the main thread stack, as below:
    polybug.png

    I also bought and installed the Panic Button plugin from asset store, and it can not abort any C# script, so I guess there maybe dead loops in tessMeshMergeConvexFaces ?
     
  2. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    109
    BTW, I'm using Unity 5.6.0f3 Personal. Both PC and Mac version has same issue.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,428
    We have a bug report for this and will get to it ASAP. What I can you is that it's a bug somewhere in the 3rd party library libtess2 which is used here to triangulate the paths. It's getting stuck in an infinite loop and sometimes even crashes. Narrowing this down is the "fun" part as so far it's only been seen on super complex paths.
     
  4. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    109
    Hi, thanks for reply, how can I follow this bug or what can I help? It is too important to my game.

    My game is heavily used PolygonCollider2D, the path is really complex, and I have spend long time to simplify the path, right now the issue is not the path point count, you know, most time it runs well, but about every 100 times, it occurs that infinite loop, make my game dead. It is really not "fun", it make me crazy.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,428
    If you could create a super simple reproduction project and create a bug report and give me the case number it might help track down the issue.

    The only other thing you could try is firing your paths to the libtess2 yourself in a test project but I understand if you're reluctant or don't have time for that.

    We effectively do this:

    Code (CSharp):
    1. // Create tesselator.
    2. TESStesselator* decomposition = tessNewTess(NULL);
    3.  
    4. // Add as many paths as you like.
    5. tessAddContour(decomposition, 2, points, sizeof(Vector2), pointsInPath);
    6.  
    7. // Do the tesselation.
    8. const int tessError = tessTesselate(decomposition, TESS_WINDING_ODD, TESS_POLYGONS, b2_maxPolygonVertices (8), 2, NULL);
    9.  
    The problem seem to come when `tessTesselate` is called. Right now we have a case of a crash
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,428
  7. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    109
    Good information, I will try to reproduction the issue path, and maybe have a try to debug it directly with libtess2, but i'm not familiar with C/C++, however, for saving my game i will definitely try. :) And of course hope you Unity engineer will have time to focus on this, i have searched the internet, there's many developers has encountered this issue.
     
  8. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    109
    Finally I reproduction it, please check the attached simple project.
    For PolyIssueTest.cs
    Code (CSharp):
    1.  
    2.     //Note, change the value to 93 or 94, you'll make Unity hanging
    3.     private int pathFile = 2;
    4.  
    There's 3 file stored path points in Assets/data/ folder, the file 2 is fine, you'll see polygon collider in scene view, if you change to load 93 or 94 (the path will be logged at starting), it will make Unity hanging.

    Hope that helps.
    BTW, I have reported this bug: https://fogbugz.unity3d.com/default.asp?905608_hospnbkdcvseio2p
     

    Attached Files:

    Last edited: Apr 27, 2017
  9. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    109
    Please note that:
    The path value in file "2" is fine, and the value in "93" and "94" will cause Unity hanging.

    So if you want to see the issue, change the pathFile value to 93 or 94 in the source code, then run.
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,428
    Thanks, good timing. I have just fixed the crash case. I will see if it solves your issue too.
     
  11. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,428
  12. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    109
    That's great, thanks for such quick done, I'll follow it.
     
  13. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    109
    Is there a way to replace libtess2 in my Unity or should I wait for next Unity update?
     
  14. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,428
    You cannot replace it, it's part of the native engine.
     
  15. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,428
    I've got a fix for both the crash and infinite loop bug cases. libtess2 is also used by the the sprite mesh generate so it needs a bunch of testing first before it lands in a release. I'll try to get that out ASAP.

    https://gyazo.com/7a8d7554e614cb5483116dbd232d5e08
     
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,428
    The fixes have just landed in 5.5.3p3 and 5.6.0p4.
     
  17. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    109
    Cool, great fast work, I'll test it soon in my game. Thank you MelvMay!
     
  18. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    109
  19. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,428
    Yes, I never said they were released yet just that they have landed in those versions. I believe the scheduled release for 5.5.3p3 and 5.6.0p4 is Wed 3rd May (tommorrow) or thereabouts.
     
  20. iileychen

    iileychen

    Joined:
    Oct 13, 2015
    Posts:
    109
    Thank you, good information, I have watched the Unity Patch Release Thread.

    PS, i saw physics2d is improving fast, appreciate the good works, seems my game has selected the best proper engine.