[Insight-users] AccessViolationException in ManagedITK

Dan Mueller dan.muel at gmail.com
Mon Oct 18 08:38:07 EDT 2010


Hi Volodymyr,

Can you post a minimal example to reproduce the issue?

I suspect that somewhere in your application you are accidentally
destroying the unmanaged memory twice (perhaps once in your unmanaged
code, then again in your managed code).

Cheers, Dan

On 18 October 2010 13:16, Volodymyr Tkachuk <vova.tkachuk at gmail.com> wrote:
>
> 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.
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list