好吧,我知道很多人都有 Release VS 的问题。调试模式。我进行了很多搜索,并检查了程序的堆栈跟踪并检查了指针。但是,我不明白为什么我的程序在调试模式下完美运行时,在发布模式下会出现访问冲突错误!在深入 ITK 代码的一些步骤之后,我突然看到一个函数导致访问冲突。我将首先介绍我的代码,然后介绍导致此访问冲突的调用层次结构:
这是我的类型定义:
//typedef unsigned char PixelType;
const unsigned int dimention = 3;
//STD types
typedef std::vector<std::string> FileNamesContainer;
typedef std::vector<std::string> SeriesUIDContainer;
//ITK Types
typedef itk::DICOMSeriesFileNames NamesGeneratorType;
typedef itk::Image <signed short, dimention> ImageType; //Defining Image Type
typedef itk::ImageSeriesReader<ImageType> ReaderType; //Defining the type of the image series reader
//GDCM Types
typedef itk::GDCMImageIO DICOMImageIOType;
这是我的功能:
ReaderType::Pointer itkReadDICOM::ReadImages(char *sourceFolderAddress, std::string &seriesUID)
{
std::cout<<"- Getting file names in: "<<sourceFolderAddress<<std::endl;
std::cout<<"- Series ID: "<<seriesUID<<std::endl;
//Creating a pointer to an object of the reader type. ReaderType is defined on top as itk ImageSeriesReader
ReaderType::Pointer reader = ReaderType::New();
//Setting the IO type by creating a dicomIO object from the GDCMImageIO. This will make sure we read DICOM images.
DICOMImageIOType::Pointer dicomIO = DICOMImageIOType::New();
reader->SetImageIO(dicomIO);
//Creating a dicom series name generator. It will generate the name of the dicom series based on the input directory.
NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
namesGenerator->SetDirectory(sourceFolderAddress);
//Getting names and passing the names to the reader to read them.
FileNamesContainer fileNames = namesGenerator->GetFileNames(seriesUID);
reader->SetFileNames(fileNames);
std::cout<<"- Reading files ... ";
//Adding a reading progress observer to the reader so we can see how are we reading.
ITKCmdProgressObserver::Pointer progressObserver = ITKCmdProgressObserver::New();
reader->AddObserver(itk::ProgressEvent(), progressObserver);
//Actually reading the files here. If any error happens it will be Printed and the program exists.
try
{
reader->UpdateLargestPossibleRegion();
std::cout<<"Successfully read "<< fileNames.size() <<" file(s)."<<std::endl;
}
catch (itk::ExceptionObject &ex)
{
std::cout<<"Failed."<<std::endl<<"*********************************************************************"<<std::endl;
std::cout<<ex<<std::endl;
std::cout<<"*********************************************************************"<<std::endl;
return 0;
}
return reader;
}
导致错误的调用是这样的:
reader->UpdateLargestPossibleRegion();
上面的函数调用经过这个最终导致错误的调用链:
1.
this->UpdateOutputInformation(); //void ProcessObject::UpdateLargestPossibleRegion()
2.
this->GenerateOutputInformation(); //void ProcessObject::Update()
3.
reader->UpdateOutputInformation(); //template <class TOutputImage> void ImageSeriesReader<TOutputImage>::GenerateOutputInformation(void)
4.
this->GenerateOutputInformation(); //void ProcessObject::UpdateOutputInformation()
5.
m_ImageIO->SetFileName(m_FileName.c_str());
m_ImageIO->ReadImageInformation(); //template <class TOutputImage, class ConvertPixelTraits> void ImageFileReader<TOutputImage, ConvertPixelTraits> ::GenerateOutputInformation(void)
在第 5 步,第一行很好,第二行导致访问冲突。它甚至不让我通过它。我正在使用 Visual Studio 2010。感谢您的回答。