Search Unity

Question Native Crash - PhysicsContacts2D::RemoveContact(std::__ndk1::pair<Collider2D const*, Collider2D cons

Discussion in 'Physics' started by SeriouslyNot, Jul 14, 2020.

  1. SeriouslyNot

    SeriouslyNot

    Joined:
    Nov 24, 2017
    Posts:
    121
    I'm having this Native Crash a lot lately:



    what does it mean and how can i fix it?

    Note: The crash happens on devices and also in Unity Editor during play mode (Unity would just crash and close) and asks me to report a Bug.
     
    Last edited: Jul 14, 2020
  2. SeriouslyNot

    SeriouslyNot

    Joined:
    Nov 24, 2017
    Posts:
    121
    @florianpenzkofer can you help please?

    UPDATE: This happens when i disable "Physics2D --> callbacks on disable", when re-enable it, the Crash doesn't happen. Is it a bug in Unity?
     
    Last edited: Jul 14, 2020
  3. florianpenzkofer

    florianpenzkofer

    Unity Technologies

    Joined:
    Sep 2, 2014
    Posts:
    479
    Sounds like a bug. Can you please creat a bug report with repro project? Please post the case number here once you have one.
     
    SeriouslyNot likes this.
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    I have just received a bug report about this and will investigate soon.
     
    SeriouslyNot likes this.
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    @FadiObaji I have fixed two high-priority bugs related to this and they're both currently under review so will land in a release ASAP.

    For your refererence: Case 1262936 and a similar case 1231211.

    NOTE: Whilst the callbacks maybe not look similar, there are a lot of duplicate cases that report this issue with your callstack. Also the fact that you can change it via "callbacksOnDisable" means it's almost 100% guaranteed to be the same issue. If you want to submit a bug report and send me the case number or just DM me a simple reproduction project with instructions I'd be happy to verify that it's fixed.
     
    Last edited: Jul 21, 2020
    SeriouslyNot likes this.
  6. SeriouslyNot

    SeriouslyNot

    Joined:
    Nov 24, 2017
    Posts:
    121
    @MelvMay



    Actually the crashes happen when i Disable the callBacksOnDisable not when Enabling it.
    It is enabled by default when creating a new project, but when disabling this feature --> crashes.

    I don't know how to make Reproduction steps because my project has a lot of scripts and prefabs, doing that in an empty project doesn't seem to cause crashes. I'll try to reproduce the crash with an empty project and send you the case.

    Note: the crashes happen when destroying gameObjects inside a List or when removing them from the List,

    This code is making the crashes:
    ClearBullets() is called on gameOver or when going to mainMenu

    Code (CSharp):
    1. private void ClearBullets()
    2.     {
    3.         if (bulletList == null) return;
    4.         foreach (var bullet in bulletList.ToArray())
    5.         {
    6.             bulletList.Remove(bullet);
    7.             Destroy(bullet.gameObject);
    8.         }
    9.         // TODO: do we need bulletList.Clear(); ?
    10.     }
    Commenting out the code make the crashes go away.

    Each bullet has a RigidBody2D, CircleCollider2D, SpriteRenderer and a BulletController script.
     
    Last edited: Jul 21, 2020
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    Yes, I mistyped that in the resolution notes. With that option on, the contacts are processed during the callback sequence however with it off, the contacts are left orhaned and cause the crash. I'll update the notes, hopefully that'll update the web-site.
     
    SeriouslyNot likes this.
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    Just to note that both the above cases have now landed in 2020.2.0a20, 2020.1.1f1 & 2019.4.7f1 none of which have been released yet.

    The public issue trackers will show this when the respective cases have been closed.
     
    SeriouslyNot likes this.
  9. SeriouslyNot

    SeriouslyNot

    Joined:
    Nov 24, 2017
    Posts:
    121
    Wow amazing!, can’t wait for 2019.4.7f1 to be released.