[Insight-users] AccessViolationException in ManagedITK

Volodymyr Tkachuk vova.tkachuk at gmail.com
Mon Oct 18 07:16:59 EDT 2010


Hello,

I'm using some wrapped ITK filters from my C# application. And after the
program ended I usually get AccessViolationException in Managed ITK's dll's.
The folowing code produces the exception:

itkManagedObjectAutoPtr.cxx

void Reset(T* ptr)
    {
        try
        {
            if ( m_ptr != NULL && ptr != m_ptr )
            {
                // Free the existing native pointer
                m_ptr->RemoveAllObservers( );
                m_ptr->SetReferenceCount( 0 );
            }

            // Set the new native pointer (sets to NULL if ptr = NULL)
            m_ptr = ptr;

            // Register the new pointer to keep it alive
            if ( m_ptr != NULL )
            {
                m_ptr->Register( );
            }
        }
        catch (...)
        {
            // HACK: Consume the exception, even though it is bad practice.
            // NOTE: This method tends to throw
System.AccessViolationExceptions,
            //       probably because the memory has been previously freed.
        }
    }

For some unknown reason the exception is not handled with try-catch (SEH is
turned on). Could it be because of .Net 4 (as I understand, ManagedITK was
originally design for .Net 2)? Or I missed some compiler options?
-- 
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/AccessViolationException-in-ManagedITK-tp5646651p5646651.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list