Closed Eideren closed 5 years ago
There are a few points to consider.
BulletObjectTracker is a work in progress thing to make sure that BulletSharp objects are disposed properly. Eventually it should also keep track of object dependencies to warn when objects are disposed in some wrong order that makes Bullet crash. The BULLET_OBJECT_TRACKING flag is currently set in the repository during development, but I'll remove it eventually.
I think I'll try implementing the single LocalConvexResult/LocalRayResult instance for all AddSingleResultUnmanaged calls, but I'm not sure when I'll get to it. I do see the need to improve performance there.
Edit: See below instead.
Result types (LocalConvexResult, LocalRayResult, ManifoldPoint, etc.) give access to write operation onto bullet-managed memory, users are also allowed to create structs of those types, what are the use cases for both of those ?
If we just marshall bullet's ptrs as new c# structures and clear the pointer right away we won't have to deal with forgetting to clear them, there won't be any concurrency issue, and when users instantiate structures of those types we also won't have to create and manage any bullet pointer as it will never interact with bullet anyway, right ? Again, I'm only talking about 'result' types but I feel like we're just making this more complex than it needs to be ?
You're right, it looks like LocalConvexResult, LocalRayResult and LocalShapeInfo are not passed into any native Bullet method and users never need to create those objects. So the classes do not have to wrap unmanaged objects and they do not require destructors or the IDisposable interface. I turned them into structs here: https://github.com/AndresTraks/BulletSharpPInvoke/commit/d9d1f231b7dc09ef5cda76a5f16ee0939eb27acd
It would be possible to initialize all members of the structs with values from the unmanaged objects and forget the native pointer, but that's probably unnecessary work. And it's not likely that someone would accidentally copy a LocalConvexResult/LocalRayResult and try to access the native memory from outside of the AddSingleResult method.
I'll look at CollisionObjectWrapper and ManifoldPoint later.
Thanks, I'll just close this one off then since your commit took care of most of the issues !
Description This PR changes a couple of data types to structs to reduces the amount of garbage generated, as those types only communicate with the C++ layer they should be safe to replace with lightweight structs. Changes The types changed are : CollisionObjectWrapper, ManifoldPoint, LocalConvexResult, LocalRayResult and LocalShapeInfo. I have also introduced a new type called 'NonZeroIntPtr' which helps in filling the features that where included with the implementation of those classes but cannot be ported to structs.
I need some clarifications though
The second commit updates the syntax used within /test, I couldn't quite get it to run to validate this PR though. If you really can't find the time to test this out I'll try to figure it out on my own.