Copy behavior of data structures

Issue #168 new
Hayk Martirosyan created an issue

Data structures like SRigidBody, SRigidBodyDyn, SForce, etc. have member variables which are pointers to other data structures to denote parents, children, etc. This inherently means that they won't copy correctly. Let's say a class has two SRigidBodies, which are referencing each other - I can't think of a good way to copy both and update the pointers in between them (except manually) to have that class copy correctly. Right now, the copy behavior is incorrect and leads to hard-to-track seg faults.

I see three options:

  1. Make sure all data structures copy properly by setting the pointers correctly (probably very hard).
  2. Change the pointers to something that does a lookup (probably a lot of time?).
  3. Explicitly forbid copying so people don't get confusing segfaults:
NonCopyable & operator=(const NonCopyable&) = delete;
NonCopyable(const NonCopyable&) = delete;

My best suggestion is do option 3 now to prevent errors, and in the longer term think about a way to handle the data structures so they copy naturally. I think it's normal for classes that hold resources (mutex, thread, open files) to delete copy constructors explicitly. This is not a case of that, but explicit compile-time error is better than segfault.

In the screenshot, we can see an example of copying a CMappedTree, but the link_ds_ inside the root nodes still point to the same entry. This becomes a seg fault when the SRigidBody it points to is destructed if the user copies some data structure containing the CMappedTree and SRigidBody.

scl_debug.png

Follow up from #167

Comments (3)

  1. Log in to comment