<div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">This may be all wrong in C#-land, but in my wee little C++ brain I would do<br>something like this:
<br><br>SceneObjectGroup should be subclassed as SceneObjectGroupPhysical for any<br>object that interacts physically. This way, constructors and destructors<br>can do the right thing wrt allocating & cleaning up physics-engine stuff.
<br></blockquote></div><br>This may be the ramblings of a mad man, since I haven't studied the physics code, I am focussing on the differences between C# and C++, so please forgive me, if I state the obvious.<br><br>Sub-classing sounds like a good strategy, but you cannot rely on the destructor to assist you in cleaning up. In .NET/Mono destructors are being called when ever the garbage collector feels like it. I think you'll need the IDisposable pattern.
<br><br>The IDisposable pattern is designed to handle situations where you <span style="font-weight: bold;">need</span> deterministic deconstruction of your class. Unfortunately the IDisposable pattern has some drawbacks.
<br><br>1) I is a little complex, when ever you inherit from a "Disposable" class, you need to set up code, which overrides the Disposable methods correctly (The good news is that there are 10 gazillion articles out there explaining how it works.)
<br><br>2) Just as with resource leaks in C/C++ and similar unmnanaged languages, people tend to forget to implement stuff in: "using(object) { ..... }" or executing the Dispose method. Only matters are even worse, because some new commers to .NET/Mono thinks that the garbage collector will solve all their problems.
<br><br>I would suggest creating an IPhysicalObject interface, which inherits from IDisposable. Then I would add that interface to SceneObjectGroupPhysical, and make sure that the physics engine only operates on the IPhysicalObject interface.
<br><br>