Hi everyone,

I just wanted to share a piece of information I discovered while developing
our custom renderer for Softimage.

We were having an issue where Soft would hang when we were extracting the
scene for rendering after deleting a light in the scene.
It turns out that the problem was cause by the fact that our plugin was
holding CRefs to objects in the scene between renders for the purpose of
determining what had changed between renders and therefore what data needed
to be re-extracted/re-processed.  During extraction, once we determined
that the light was no longer in the scene, we would delete our tracking
object which included a CRef to the deleted light.  The destruction of the
CRef was hanging Soft.  Apparently the problem is caused by the fact that
CRef represents a *strong* reference to an object.  So, if you have a CRef
to something (say a light) and you delete the light in Soft, the light
doesn't actually get deleted because it is still being referenced by that
CRef.  For whatever reason, I had assumed that a CRef was a weak reference
and that the CRef would simply become invalid when the referenced object
was deleted.  Instead, the light is only deleted when the last CRef is
destroyed, which in our case was causing a hang because it
was happening during our custom renderer's "Process" callback which Soft
calls on a special render thread and not the main thread.  We eventually
solved the problem by tracking objects by their object ID rather than using
CRefs between renders.

Long story short - CRef is a strong reference.  I assumed it was a weak
reference.  Don't make the same mistake!
Too bad this isn't documented and too bad the SDK doesn't provide an
equivalent to CRef that simply becomes invalid when it's referenced object
is destroyed.

-Nicolas

Reply via email to