Fix a potential bug exposed by the memory checker code.
When writing test cases, I found a problem with with this code:
OSG::TransformNodePtr? xnode;
xnode = OSG::TransformNodePtr::create()
What hapens is:
~CoredNodePtr?() is called and calls setCore(NodeCorePtr?(NullFC)) which calls
setCore(cast_dynamic<CorePtr?>(pCore))
with a NULL pCore. The implementation of cast_dynamic calls getCPtr on the in parameter which in this case means it calls getElemP with a NULL fc.
The memory checker detects this case because it actually tries to use the cptr returned (instead of just casting it) and causes a seg fault. I think it seems like
a bad way for dynamic cast to behave so I added code that detects this case and just returns Null directly.
I fixed the code up by making cast_dynamic detect the case of a NULL fcptr and automatically return NULL instead of trying to do anything with the fc (such as
getCPtr()).
Note: I am not sure this is the "best" way to fix the problem, but it was the method that seemed to be the easiest to me.
|