AndresTraks / BulletSharpPInvoke

.NET wrapper for the Bullet physics library using Platform Invoke

Home Page:http://andrestraks.github.io/BulletSharp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BulletObjectTracker is not thread safe

patricksuo opened this issue · comments

commented

Bullet/BulletSharp is not thread-safe in general.
You should synchronize threads when accessing BulletObjectTracker or any other Bullet objects.

commented

I ran into AV crash in multi-thread app with BULLET_OBJECT_TRACKING flag enabled.
But I can not reproduce without BULLET_OBJECT_TRACKING flag.
So I look into what BULLET_OBJECT_TRACKING is guarding.

I found this hashset might be access by multi-thread without synchronization:

public HashSet<BulletObject> UserOwnedObjects { get; set; } = new HashSet<BulletObject>();

If you have multiple bullet instances on different threads, it could be problematic.

#if BULLET_OBJECT_TRACKING
public static BulletObjectTracker Current { get; } = new BulletObjectTracker();
internal static void Add(BulletDisposableObject obj)
{
Current.AddRef(obj);
}
internal static void Remove(BulletDisposableObject obj)
{
Current.RemoveRef(obj);
}

That's a good point. I added synchronization: 83fd5ea

commented

Thanks.