Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnhandledException : Removing object that is not being tracked. at Finalize() #58

Closed
jack81722 opened this issue May 7, 2019 · 2 comments

Comments

@jack81722
Copy link

I am developing a power server that will create multiple rooms and multiple physic worlds. My simple game object wrapping BulletSharp.CollisionObject will be added or removed at the end of frame like below code :

public void Unregister(SimpleGameObject go)
{    
    if (world.CollisionObjectArray.Contains(go.collision))
    {
        world.RemoveCollisionObject(go.collision);
        go.collision.Dispose();
    }
}

Sometime it will throw an exception such as :

Unhandled Exception: System.Exception: Removing object that is not being tracked. Object info: BulletSharp.CollisionObject
   at BulletSharp.BulletObjectTracker.RemoveRef(BulletDisposableObject obj)
   at BulletSharp.BulletObjectTracker.Remove(BulletDisposableObject obj)
   at BulletSharp.BulletDisposableObject.Finalize()

It looks like that physic world lost dependence of collision object while GC calling Finalize() method. What may I do to solve this problem? It also will happen when disposing ray result callback after using RayTest() method :

public bool RaycastAll(Vector3 origin, Vector3 direct, out List<Vector3> hitPoints, out List<CollisionObject> hitObjs, int mask = -1)
{
    Vector3 from = origin, to = origin + direct;
    AllHitsRayResultCallback callback = new AllHitsRayResultCallback(from, to);
    callback.CollisionFilterMask = mask;
    world.RayTest(from, to, callback);
    hitPoints = callback.HitPointWorld;
    hitObjs = callback.CollisionObjects;
    return callback.HasHit;
}
@AndresTraks
Copy link
Owner

Is it a multithreaded application?

I added synchronization here: AndresTraks/BulletSharpPInvoke#54
and I assume you're using the P/Invoke version of BulletSharp.

@jack81722
Copy link
Author

Thanks for reply.

Yes, it's a multithreaded application.
I used the newest version of BulletSharpPInvoke and then no error anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants