A SERVICE OF

logo

Scene Graph Base Classes
3
The csObject Class
The csObject class is the base class for all objects in a scene; where an object is an entity
that you can place in the scene graph. A csObject provides reference counting and
runtime typing for all its children.
Reference Counting
Many kinds of data objects in Cosmo 3D can be placed in a hierarchical scene graph.
Using instancing, an object can be referenced multiple times. Scene graphs can become
quite complex, which can cause problems if youre not careful. Deleting objects can be a
particularly dangerous operation, for example, if you delete an object that another object
still references.
Within each csObject is a counter that keeps track of the number of objects referencing a
particular instance. Reference counting provides a bookkeeping mechanism that makes
object deletion safe: an object should never be deleted if its reference count is greater than
zero. In general, you should only unreference an object in case it is referenced by another
object.
It is just as important, however, not to unreference an object that has not been referenced.
Because the reference count is an unsigned integer, unreferencing an object that has not
been referenced decrements the reference count from 0 to a large positive number and it
will never be deleted.
Each csObject is created with a reference count of 0. It is important to reference an object
when it is created to make sure that someone else does not delete it when they
unreference it.
When object A is attached to object B, the reference count of A is incremented.
Additionally, if A replaces a previously referenced object C, the reference count of C is
decremented.