Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Crashes in PhysicsScene2D::UpdateJoints(float)

Discussion in 'Physics' started by madfatcat, Jul 29, 2019.

  1. madfatcat

    madfatcat

    Joined:
    Jul 3, 2014
    Posts:
    14
    Hey all,
    I make a 2D physics puzzle game for iOS. The game is live on App Store and I keep receiving a lot of crash reports in xCode. I cannot reproduce this crash and my question is: what will be my next steps to fix this bug? My game utilizes a lot of 2d joints, I use 2019.1.11f1.

    Crash report:

    Thread 0 Crashed:
    0 mygame 0x0000000102b9d3a0 PhysicsScene2D::UpdateJoints(float) + 88 (Joint2D.h:55)
    1 mygame 0x0000000102b82f20 PhysicsManager2D::Simulate(PhysicsScene2D*, float) + 1172 (PhysicsManager2D.cpp:775)
    2 mygame 0x0000000102b82a7c PhysicsManager2D::FixedUpdate() + 124 (PhysicsManager2D.cpp:525)
    3 mygame 0x0000000102a2c66c ExecutePlayerLoop(NativePlayerLoopSystem*) + 88 (PlayerLoop.cpp:281)
    4 mygame 0x0000000102a2c6a0 ExecutePlayerLoop(NativePlayerLoopSystem*) + 140 (PlayerLoop.cpp:298)
    5 mygame 0x0000000102a2c888 PlayerLoop() + 236 (PlayerLoop.cpp:354)
    6 mygame 0x0000000102ce8080 UnityPlayerLoopImpl(bool) + 52 (LibEntryPoint.mm:0)
    7 mygame 0x000000010252b5d0 UnityRepaint + 140 (UnityAppController+Rendering.mm:276)
    8 mygame 0x000000010252b4bc -[UnityAppController(Rendering) repaintDisplayLink] + 88 (UnityAppController+Rendering.mm:71)
    9 QuartzCore 0x00000002416b2ea8 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 632 (CADisplay.mm:2349)
    10 QuartzCore 0x0000000241780858 display_timer_callback(__CFMachPort*, void*, long, void*) + 276 (CADisplayTimer.cpp:163)
    11 CoreFoundation 0x000000023d1fb058 __CFMachPortPerform + 192 (CFMachPort.c:522)
    12 CoreFoundation 0x000000023d222af0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 60 (CFRunLoop.c:1996)
    13 CoreFoundation 0x000000023d2221e8 __CFRunLoopDoSource1 + 444 (CFRunLoop.c:2133)
    14 CoreFoundation 0x000000023d21cd80 __CFRunLoopRun + 2060 (CFRunLoop.c:3152)
    15 CoreFoundation 0x000000023d21c254 CFRunLoopRunSpecific + 452 (CFRunLoop.c:3247)
    16 GraphicsServices 0x000000023f45bd8c GSEventRunModal + 108 (GSEvent.c:2245)
    17 UIKitCore 0x000000026a5644c0 UIApplicationMain + 216 (UIApplication.m:4353)
    18 mygame 0x00000001025247b0 main + 160 (main.mm:41)
    19 libdyld.dylib 0x000000023ccd8fd8 start + 4
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    I've not seen any crash reports and there are no existing bug reports unfortunately in this area. That particular line is where it iterates joints that have a non-infinite break force/torque limit set. It iterates all those joints and gets the break force and torque before comparing it to what happened. The specific line above is getting the property "BreakForce" on the joint so the joint pointer must be corrupt and I've no idea how that can happen.
     
  3. madfatcat

    madfatcat

    Joined:
    Jul 3, 2014
    Posts:
    14
    Thanks MelvMay. One quick question: have there been any changes in this part of physics engine between 2018.2.12f1 and 2019.1.11f1 ?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    Nope, that function hasn't changed in a very long time but it's also so simple and the only thing that can be wrong is that the joint pointer is invalid so something indirect is causing that elsewhere.

    Are you using multiple local physics scenes? Are you actually using joints with non-infinite break limits? Are joints destroyed explicitly?
     
  5. madfatcat

    madfatcat

    Joined:
    Jul 3, 2014
    Posts:
    14
    One scene, a lot of spring joints and hinge joints, spring joints have non-infinite break forces and yes, many springs and hinges are destroyed explicitly.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    I can see several editor crash reports for "PhysicsScene2D::UpdateJoints" on our Crash Analyzer but only on Windows:

    - 2018.4.3f1 on 5th, 10th & 23rd July 2019
    - 2019.1.1f1 on 4th July 2019
    - 2018.3.3f1 20th April 2019
    - 2018.3.7f1 12th March 2019

    None are associated with a bug report unfortunately but instead are automatic editor crash reports. :(

    The only thing I can think of to isolate the issue is to set-up a serious stress test doing exactly what you're doing. Being as you have better knowledge of the behaviour, it would be good if you could help there. It sounds like a bunch of joints (many?) breaking limits but also joints being explicitly destroyed and I can assume more joints being added?

    If you do have anything that could be used to stress this and could send it to me then I'd be happy to help isolate the issue.
     
    Last edited: Jul 30, 2019
  7. aegis123321

    aegis123321

    Joined:
    Jul 5, 2015
    Posts:
    71
    It happened several times on my application which is on Windows.
    I found it by crash.dmp, it crashed on

    > UnityPlayer.dll!PhysicsScene2D::UpdateJoints(float)

    And it seems to access the invalid pointer, but I can't reproduce it.

    The only thing I know is that it happened when I destroyed lots of objects including joints.

    Environment: 2019.4.17f1, Windows, IL2CPP

    Is there any thing I can do to solve this problem?
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    A crash in the same method doesn't mean it's the same thing although in this case it's likely and I've never seen a bug report for this.

    If you can reproduce this in a simple project in a bug report then it can be looked at.

    That method is where the joint-limits are processed so it sounds like (somehow) joints are removed but their list of joint-limits are not which is very strange. A quick look through the code doesn't show anything obvious and the unit test shows them being removed so something more complex is happening. Still, it has to be related to joint-limits not being removed.
     
    Last edited: Feb 14, 2021
    aegis123321 likes this.
  9. Naotagrey

    Naotagrey

    Joined:
    Apr 17, 2016
    Posts:
    37
    Has there been progress on this issue ?
    I've been encountering the same thing, and it's very weird to me...

    I have a simulation-type project where Joint2D can be created and destroyed at will by the agents so my guess is that a lot of them are created/destroyed. The issue usually occurs after 10 to 20 hours of runtine so it's very hard to isolate what caused the error and to replicate it.

    Not all users report that crash but it's indeed concerning since the purpose of the game is to allow for long-running simulations.

    Is there something I can do to help solve that issue? A bug repport I can make? Something like that?
    Thanks a lot
     

    Attached Files:

  10. aegis123321

    aegis123321

    Joined:
    Jul 5, 2015
    Posts:
    71
    I think it won't be in progress unless we have a simple project to reproduce it easily and quickly.
    It has still been happening in our project.:(
    And the only thing I know is it happens after destroying the joints with limits at very random moment.
     
  11. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    So today I finally got a bug report on this issue (2 years after the first post here) which I believe is from you (was created this month). QA are trying to duplicate it and I've spent several hours going through to see what could possibly cause this. I've not seen anything conclusive but I have spotted something even though it's not clear how it might cause the issue.

    I could certainly make a modification and produce you a custom build that would allow you to test to see if it resolves it. Obviously QA here will continue doing the same.

    The bug report project is 2020.3.4f1 so it'd be a build based on the latest 2020.3. Note that the build version would NOT be supported and would not guarantee anything else being 100% functional but would be to test this issue only. Basically a bunch of words to say, don't use this in production, for testing only.

    If you are willing to do that then I can produce a build. Please don't get your hopes up too high though because this is a total guess but certainly something that is wrong that should be fixed. Given how long this seems to have been going on and the fact that this is the first time I've had a bug report on it, I'd like to expedite possible fixes. If it doesn't fix it then we know and we can look at other stuff while QA try to isolate it.

    Any build links would be sent privately, not to be distributed. I've set a build package running on our build farm.
     
    EZaca likes this.
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    I have responded to your bug report by providing you with a custom build for you to test. I would appreciate if you could acknowledge that you've received it.

    Thanks.
     
  13. Naotagrey

    Naotagrey

    Joined:
    Apr 17, 2016
    Posts:
    37
    Sorry, I was moving house,

    I'll try it out and let you know, thanks a lot!!
     
    MelvMay likes this.
  14. Naotagrey

    Naotagrey

    Joined:
    Apr 17, 2016
    Posts:
    37
    It seemed to have resolved the issue, I did not manage to reproduce the error using the custom build!
    It's hard to 100% guarantee considering the nature of the crash/bug, but I think it's reliable enough

    Thanks a lot :D!

    Would you know what kind of timeframe we can expect before the fix is available with an official release?
     
  15. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    Unfortunately there's no way to give you anything resembling an accurate answer. The fix is already in progress however it has to land in our mainline trunk first at which point all the backports can then go into their respective branches. Whenever the next release is for those branches is when you'll see it. It'll be at least a few weeks before it's in an actual release.

    I'll post back here as each lands if that'll help.
     
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    I've just queued the fix PR against our trunk (2022.1) and backport PRs to 2021.2, 2021.1 and 2020.3 which will land sometime after trunk has landed.
     
    Naotagrey likes this.
  17. aegis123321

    aegis123321

    Joined:
    Jul 5, 2015
    Posts:
    71
    I'm glad to see this problem will be resolved
    I would appreciate if there is anyway to avoid the problem from old version or someone know the most possible reason caused the crash.
     
  18. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    Impossible to say without you actually saying which version.
     
  19. aegis123321

    aegis123321

    Joined:
    Jul 5, 2015
    Posts:
    71
    we're working on 2019.4 but it's also good to know how it happens on 2020.3.4f1 which the reported case.
     
  20. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    The problem has been around for many years (it's in Unity 5) but nobody submitted a single bug report so we've been unable to resolve and verify a fix until now.
     
  21. aegis123321

    aegis123321

    Joined:
    Jul 5, 2015
    Posts:
    71
    Then how to avoid this problem in 2019.4? I thought you've already known how it happen and fixed it? Just wanna know how it happens.

    It's okay If it's just too complicated to explain.
     
    Last edited: Jul 14, 2021
  22. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    I'm not sure how I can explain how the engine code causes this or what good it would do you. You cannot "avoid" it.

    We can look at seeing if it'd be allowed backported to 2019.4 but it's already going to be in three backports (which is exceptional) including a LTS.
     
  23. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
  24. aegis123321

    aegis123321

    Joined:
    Jul 5, 2015
    Posts:
    71
  25. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    Just an update.

    It has landed in
    • 2022.1.0 a4
    • 2021.2.0 b6
    • 2021.1.17f1
    • 2020.3.16 f1
    It hasn't yet landed in:
    • 2019.4
     
    EZaca, Naotagrey and Menion-Leah like this.
  26. Naotagrey

    Naotagrey

    Joined:
    Apr 17, 2016
    Posts:
    37
    Thanks a lot :D
    You've been really helpful and patient, just wanted to show my enormous appreciation!
     
    EZaca and MelvMay like this.
  27. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,589
    Final note, it has also now landed in 2019.4.30f1 so available there too when it's released.

    That concludes the fixes. If you could confirm that you no longer see it, I'll pass that info along to QA to close the cases.

    NOTE: It might still show as "in review" in the link but the fixes have landed. Only when the QA closes those cases will it show correctly.
     
    EZaca, Naotagrey and aegis123321 like this.