Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug / Crash  Error Destroy ObiCollider
#1
Hi Jose,

I spotted something weird when the ObiCollider are destroyed in my project.
I procedurally generate a rope and its blueprint at runtime (similar to your scene RopeGrapplingHook ). Everything looks good and it's working.
However, every time when I turn off the play mode, I got this error :

ArgumentNullException: Value cannot be null.
Parameter name: key
System.Collections.Generic.Dictionary`2[TKey,TValue].Remove (TKey key) (at <599589bf4ce248909b8a14cbe4a2034e>:0)
Obi.ObiMeshShapeTracker.Destroy () (at Assets/Obi/Scripts/Common/Collisions/ColliderTrackers/Trackers3D/ObiMeshShapeTracker.cs:131)
Obi.ObiColliderBase.RemoveCollider () (at Assets/Obi/Scripts/Common/Collisions/ObiColliderBase.cs:216)
Obi.ObiColliderBase.OnDestroy () (at Assets/Obi/Scripts/Common/Collisions/ObiColliderBase.cs:276)

The issues doesn't appear on all ObiCollider, I've more than 1000 ObiCollider in my scene and this error appears on about 100 of them.
So I fixed that by adding an additional check before the Remove in the Destroy method of the ObiMeshShapeTracker class (line 121) :


Code:
public override void Destroy()
{
    base.Destroy();

    MeshCollider meshCollider = collider as MeshCollider;

    if (meshCollider != null && handles != null)
    {

        handles.Unref(); // Decrease handles refcount.

        if (handles.RefCount <= 0)
        {
            if (meshCollider.sharedMesh != null && meshDataCache.ContainsKey(meshCollider.sharedMesh))
            {
                meshDataCache.Remove(meshCollider.sharedMesh);
            }
        }

    }
}



Moreover, although my rope is well initialized and works fine, if I turn off the play mode and turn it on again, I get this error :

NullReferenceException: Object reference not set to an instance of an object
Obi.ObiRopeBlueprint+<Initialize>d__2.MoveNext () (at Assets/Obi/Scripts/RopeAndRod/Blueprints/ObiRopeBlueprint.cs:56)
Obi.ObiActorBlueprint+<Generate>d__68.MoveNext () (at Assets/Obi/Scripts/Common/Blueprints/ObiActorBlueprint.cs:300)
Obi.ObiActorBlueprint.GenerateImmediate () (at Assets/Obi/Scripts/Common/Blueprints/ObiActorBlueprint.cs:278)
Obi.ObiRopeBlueprintBase.OnValidate () (at Assets/Obi/Scripts/RopeAndRod/Blueprints/ObiRopeBlueprintBase.cs:50) 

I suppose it's could be related to the rope creation at runtime or maybe a memory leak during the rope or blueprint destruction ?

Thanks in advance
Reply


Messages In This Thread
Error Destroy ObiCollider - by Chess - 03-09-2020, 03:50 PM
RE: Error Destroy ObiCollider - by josemendez - 04-09-2020, 07:23 AM
RE: Error Destroy ObiCollider - by Chess - 04-09-2020, 04:25 PM