[Insight-users] Run-Time Check Failure

Dominique Belhachemi domibel at cs.tu-berlin.de
Sat Feb 19 10:16:26 EST 2005


Dear list-members,


Problem under Windows - Visual Studio-compiled program stops with 
runtime-error

Debug-message:
"Run-Time Check Failure #0 - The value of ESP was not properly saved
across a function call. This is usually a result of calling a
function declared with one calling convention with a function
pointer declared with a different calling convention."

caused by cylinderSpatialObject::SetRadius / 
cylinderSpatialObject::SetHeight method-calls... What is the problem?
Tried out different calling-conventions -
but none of them seems to work - only _cdecl compiles
gcc has no problems with that


Best regards
Dominique 
-------------- next part --------------
#include "itkImage.h"
#include "itkImageFileWriter.h"
#include "itkGroupSpatialObject.h"
#include "itkCylinderSpatialObject.h"
#include "itkSpatialObjectToImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"


int main( int argc, char *argv[] )
{
	const int Dimension = 3;
	typedef itk::GroupSpatialObject< Dimension >     GroupType;
	typedef itk::CylinderSpatialObject     CylinderType;

	typedef itk::Image< float, Dimension >     ImageType;
	typedef itk::Image< unsigned char, Dimension > OutputImageType;
	typedef itk::ImageFileWriter< OutputImageType >     WriterType;
	typedef itk::RescaleIntensityImageFilter< ImageType, OutputImageType >     CastFilterType;
	typedef itk::SpatialObjectToImageFilter< GroupType, ImageType >     SpatialObjectToImageFilterType;


	GroupType::Pointer group = GroupType::New();

	CylinderType::Pointer cylinder1 = CylinderType::New();
	CylinderType::Pointer cylinder2 = CylinderType::New();
	double radius1 = 10.0;
	double height1 = 20.0;
	double radius2 = 10.0;
	double height2 = 20.0;





	//Problem under Windows - Visual Studio-compiled program stops with runtime-error
	//Debug-message: "Run-Time Check Failure #0 - The value of ESP was not properly saved 
	//across a function call.  This is usually a result of calling a 
	//function declared with one calling convention with a function 
	//pointer declared with a different calling convention."
	//appears on all of the next 4 method-calls... What is the problem?
	//Tried out different calling-conventions - 
	//but none of them seems to work - only _cdecl compiles
	//gcc has no problems with that
	cylinder1->SetRadius(radius1);
	cylinder1->SetHeight(height1);
	cylinder2->SetRadius(radius2);
	cylinder2->SetHeight(height2);





	group->AddSpatialObject(cylinder1);
	group->AddSpatialObject(cylinder2);

	CylinderType::TransformType::OffsetType offset;

	offset[0] = 0.0;
	offset[1] = 0.0;
	offset[2] = 0.0;
	cylinder1->GetObjectToParentTransform()->SetOffset(offset);
	cylinder1->ComputeObjectToWorldTransform();

	offset[0] = 50.0;
	offset[1] = 50.0;
	offset[2] = 50.0;
	cylinder2->GetObjectToParentTransform()->SetOffset(offset);
	cylinder2->ComputeObjectToWorldTransform();

	double scale[3];
	scale[0]=1;
	scale[1]=2;
	scale[2]=2;

	cylinder1->GetObjectToParentTransform()->SetScaleComponent(scale);
	cylinder1->ComputeObjectToWorldTransform();

	// scalierungsfaktoren
	const double* d = cylinder1->GetObjectToParentTransform()->GetScaleComponent();
	std::cout << d[0] << " " << d[1] << " " << d[2] << std::endl;

	cylinder1->GetObjectToParentTransform()->Print(std::cout);

	SpatialObjectToImageFilterType::Pointer imageFilter = SpatialObjectToImageFilterType::New();
	imageFilter->SetInput( group );
	ImageType::SizeType size;
	size[ 0 ] = 128;
	size[ 1 ] = 128;
	size[ 2 ] = 128;
	imageFilter->SetSize( size );
	imageFilter->Update();

	CastFilterType::Pointer castFilter = CastFilterType::New();
  	castFilter->SetOutputMinimum(   0 );
  	castFilter->SetOutputMaximum( 255 );
  	castFilter->SetInput( imageFilter->GetOutput() );

	const char * outputFilename = argv[1];
	WriterType::Pointer writer = WriterType::New();
	writer->SetFileName( outputFilename );
	writer->SetInput( castFilter->GetOutput() );
	try 
    {
	    writer->Update(); 
    }
	catch( itk::ExceptionObject & err ) 
    {
		std::cout << "ExceptionObject caught !" << std::endl; 
		std::cout << err << std::endl; 
		return -1;
    }
	return 0;
}


More information about the Insight-users mailing list