Search code examples
c++visual-studio-2008qtexceptionitk

Exception when execute update() of an itk::writertype


I have an image in an “itk::image::Pointer salida”. I have checked that it has the correct pixelvalues. I want to save the image into a file, but in the last line, it gives me an exception and now I don’t know what to do:

// Saving the result into a file
salida = ui.imageframe->imagereader;
writer = itk::ImageFileWriter<ImageType>::New(); 
writer->SetInput( salida ) ; 
writer->SetFileName ( "output.jpeg");
writer->Update();// ---> EXCEPTION!!

The exception goes to xmtx.c file ( mutex[mutual exclusion] support for VC++), It goes to the last line of this part of the code:

_RELIABILITY_CONTRACT
void  __CLRCALL_PURE_OR_CDECL _Mtxlock(_Rmtx *_Mtx)
{   /* lock mutex */
#ifdef _M_CEE
System::Threading::Thread::BeginThreadAffinity();
#endif
EnterCriticalSection(_Mtx);
}

Does any of you have had the same problem? Any hint for fixing it?

Thanks in advance

Antonio Gómez Barquero


Solution

  • Try catching the exception and see what it contains. I am not familiar with itk but looking at the API, the following should work:

    try
    {
        writer->Update();
    }
    catch( itk::ExceptionObject& ex )
    {
        qDebug() << ex.what();
    }
    

    This should lead you to the source of the exception.