internal virtual IntPtr NonConstPointer()
        {
            if (IntPtr.Zero == m_ptr && m_subobject_index >= 0 && m__parent != null)
            {
                Rhino.Geometry.PolyCurve pc = m__parent as Rhino.Geometry.PolyCurve;
                if (pc != null)
                {
                    IntPtr pPolyCurve = pc.NonConstPointer();
                    IntPtr pThis      = UnsafeNativeMethods.ON_PolyCurve_SegmentCurve(pPolyCurve, m_subobject_index);
                    return(pThis);
                }

                Rhino.Geometry.BrepLoop loop = this as Rhino.Geometry.BrepLoop;
                if (loop != null)
                {
                    IntPtr pBrep = loop.Brep.NonConstPointer();
                    return(UnsafeNativeMethods.ON_BrepLoop_GetPointer(pBrep, loop.LoopIndex));
                }
            }

            NonConstOperation(); // allows cached data to clean up
            return(m_ptr);
        }
        internal virtual IntPtr NonConstPointer()
        {
            if (IntPtr.Zero != m_ptr)
            {
                // m_ptr points ot an ON_Object.
                // Repair corruption that causes crashes in breps and meshes.
                // The parameters 0,0 mean:
                // The first 0 paramter = bReplair and means detect but do not repair - so exception handler can see the damaged original information.
                // The second 0 parameter = bSilentError means call C++ ON_ERROR() so a dev running a debug build gets a chance to see
                // the corrupt brep/mesh immediately.
                if (PerformCorruptionTesting && 0 != UnsafeNativeMethods.ON_Object_IsCorrupt(m_ptr, 0, 0))
                {
                    throw new CorruptGeometryException(m_ptr, this);
                }
            }
            else if (m_subobject_index >= 0 && m__parent != null)
            {
                Rhino.Geometry.PolyCurve pc = m__parent as Rhino.Geometry.PolyCurve;
                if (pc != null)
                {
                    IntPtr ptr_polycurve = pc.NonConstPointer();
                    IntPtr ptr_this      = UnsafeNativeMethods.ON_PolyCurve_SegmentCurve(ptr_polycurve, m_subobject_index);
                    return(ptr_this);
                }

                Rhino.Geometry.BrepLoop loop = this as Rhino.Geometry.BrepLoop;
                if (loop != null)
                {
                    IntPtr ptr_brep = loop.Brep.NonConstPointer();
                    return(UnsafeNativeMethods.ON_BrepLoop_GetPointer(ptr_brep, loop.LoopIndex));
                }
            }

            NonConstOperation(); // allows cached data to clean up
            return(m_ptr);
        }