I am trying to correctly dispose a scene graph from C# via swig wrapped open scene graph nodes. If I dispose of an osg node, I may get back to it via another pointer later on, so that I would call a method on the osg node which has already been disposed.
I can't catch the Exceptions it seems (I added the Exception Handling from the documentation, but since the exception is thrown in a .cs file created by swig, I guess that is not correct), but neither can I check whether the HandleRef null
, since Handle
is not public.
The following code is from a .cs file created by swig, I only added the comment to show which Exception is thrown and where:
public Node get() {
IntPtr cPtr = osgPINVOKE.NodeRef_get(swigCPtr);
//the NodeRef_get throws an AccessViolationException,
//the Handle of swigCPtr is 0 and Wrapper is null
Node ret = (cPtr == IntPtr.Zero) ? null : new Node(cPtr, false);
return ret;
}
Now my question is: how can I check if the Handle of my swig wrapped osg node is valid (i.e. not null)? Alternatively, how can I pass the exception to my calling code?