Obi Official Forum
Bug / Crash Error Destroy ObiCollider - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Bug / Crash Error Destroy ObiCollider (/thread-2466.html)



Error Destroy ObiCollider - Chess - 03-09-2020

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


RE: Error Destroy ObiCollider - josemendez - 04-09-2020

Hi there,

I could reproduce the first one. It will happen when a MeshCollider whose sharedMesh is null is destroyed. This is a bug in Obi (thanks for finding and reporting it!), and the fix is as easy as checking if the sharedMesh is null before looking for it in the meshDataCache -just like you did- as it's not necessary to reduce the reference count of a mesh that does not exist. However it's pretty unusual to have a collider referencing no mesh, so this might be indicative of a deeper problem in your scene.

The second one I could not reproduce, though. The error points to the rope being unable to destroy its first particle group (first control point), but a rope should always have at least 2 control points, this is ensured throughout the code. Can you share how you're initializing the rope at runtime?


RE: Error Destroy ObiCollider - Chess - 04-09-2020

Thanks Jose, indeed I've probably something not logic in my scene, I'll take a look !
Finally for the second point, I just tried my code on the last version of Obi (5.5) and I don't have the error. So yes, I think that's is probably an issue with my version of Obi (5.2) or Unity (2019.2). But for technical reasons I prefer to stay on Unity 2019.2, so I will not upgrade to the 5.5 which is tagged 2019.3.1 on the asset store.

That's strange because before I didn't have this error, it suddenly appeared. I wonder if my Obi plugin is probably corrupted. I would appreciate it if you could send me the 5.2 version or the last version compatible with Unity 2019.2.7. I will mail you on the Obi support email.

Thank you  !