[Insight-users] crash with release build - not because of uninitialized variable?

Ryan Guan ryan.guan at yahoo.com
Tue Dec 13 18:57:12 EST 2011


Hi All,

I attached a simple test code basically reading in an image, and I just realized that it will crash at ImageReader->Update() [actually at  ITKProcessObject::GenerateOutputInformation() ] when I compile at release mode but was fine at Debug mode. 
I searched in the mailing list, and (thought) I have ruled out the cause of uninitialized variable or destructed smartpointer, so I came up with this test code and the problem is still there! 
I would appreciate if anyone can help to find what's the problem? Thanks a lot!

IDE: windows7 Visual Studio 2008
ITK/Application: 3.20.0 

Here are the link of the code and the CMakeList, I also paste the code at the end.

http://dl.dropbox.com/u/1906263/CrashTest.cxx

http://dl.dropbox.com/u/1906263/CMakeLists.txt


#include "itkImage.h"
#include <time.h>
#include <iostream>
#include <fstream>
#include <windows.h>
#include "itkTextOutput.h"
#include "itkImageFileReader.h"
using namespace std;

typedef itk::Image< unsigned char, 2>  ImageType;
// typedef ImageType::Pointer ImagePtr;
typedef itk::ImageFileReader< ImageType > ImageReaderType;


int main(int argc, char** argv)
{
itk::OutputWindow::SetInstance(itk::TextOutput::New().GetPointer());

const std::string refImgName = "file path";

ImageReaderType::Pointer  ImageReader  = ImageReaderType::New();

ImageReader->DebugOn();

ImageReader->SetFileName(refImgName);

std::cout << "reader count at beginning "<<ImageReader->GetReferenceCount() << std::endl;

ImageType::Pointer OutputPointer = ImageType::New();
OutputPointer = ImageReader->GetOutput();

std::cout << "reader count after GetOutput " << ImageReader->GetReferenceCount() << std::endl;

std::cout << "pointer count "<<OutputPointer->GetReferenceCount() << std::endl;


try
{
ImageReader->Update();
}
catch( itk::ExceptionObject & err ) 
{ 
cerr << "ExceptionObject caught in DIR4dvf::ReadImg !" << endl; 
cerr << err << endl; 
throw err;
} 

std::cout << "reader count after update "<<ImageReader->GetReferenceCount() << std::endl;

return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20111213/6c97a540/attachment.htm>


More information about the Insight-users mailing list