简体   繁体   中英

C++ code crashed when using vector push_back in RELEASE configuration

I have a problem using c++ vectors when I build the solution in release configuration by Visual Studio 2008. The code works fine in Debug configuration. I have searched online and did not find a solution that solves the issue that I have.

Here is the explanation of my code. I have defined a class as follows. This class stores some parameters for a plane including its location in space, etc.

class PIVPlaneConfig{

public:
int update(){                       

    // Create the frame list for the PIV plane.
    for ( int   i = ListStart ;
                i <= ListEnd;
                i = i + ListStep){  
        FramesList.push_back(i);            
    }

    return 0;
};  

~PIVPlaneConfig(){
    DirRaw          = "";
    DirProcessed    = "";
    FnamePreVel     = "";

    // Reset frames list
    FramesList.clear();
};

std::string DirRaw;
std::string DirProcessed;
std::string FnamePreVel;
double pivScaleFactor;
double pivUnitFactorXY;
double pivUnitFactorVxVy;
Point2D planeOriginLocal;
Point3D planeOriginGlobal;
Point3D planeNormal;

bool CS;
int OutOfPlaneVelocity;

// Image Processing Configuration.
std::string FnamePreRawImage;
std::string FnameMaskImage;
int ElemShape;
int ElemShapeCols;
int ElemShapeRows;
Point2D ElemShapeAnchor;     
int pivResolutionHorizontal;
int pivResolutionVertical;

// File listing.
int ListStart;
int ListStep;
int ListEnd;
std::vector < int > FramesList;
int nPlanes;

};

I have a function in which I configure 12 different PlaneConfigs:

int PlaneConfigInit( int FileIndexStart, int FileIndexStep, int FileIndexEnd, vector < PIVPlaneConfig >& Planes )

Each PlaneConfig will be initialized as follows in the function PlaneConfigInit. For simplicity, I only brought the initialization of PLANE01.

double CatiaScalingFactor = 3.8 / 84.839;

PIVPlaneConfig Plane;   

// PLANE01
pivPlane.DirRaw = "Y:\\Rectangular\\Sagittal_01_001";
pivPlane.DirProcessed = "Y:\\Rectangular\\Sagittal_01_001\\Processed";
pivPlane.FnamePreVel = "Sagittal_01_";
pivPlane.FnamePreRawImage = "Sagittal_01_";
pivPlane.OutOfPlaneVelocity = FR3D_MISSING_OUT_OF_PLANE_W;

//  File list.
pivPlane.ListStart = FileIndexStart;
pivPlane.ListStep = FileIndexStep;
pivPlane.ListEnd = FileIndexEnd;

pivPlane.planeOriginLocal.x = 0;
pivPlane.planeOriginLocal.y = 0;

pivPlane.planeOriginGlobal.x = -39.206  * CatiaScalingFactor;
pivPlane.planeOriginGlobal.y = 100.0    * CatiaScalingFactor;
pivPlane.planeOriginGlobal.z = -52.316  * CatiaScalingFactor;

//  Plane unit normal vector.
pivPlane.planeNormal.x = 0;
pivPlane.planeNormal.y = 0;
pivPlane.planeNormal.z = 1.0;   

pivPlane.CS = FR3D_CS_RECT;
pivPlane.update();  
pivPlanes.push_back( pivPlane );    
pivPlane.~PIVPlaneConfig(); 

I exactly use the above code for the second plane and continue this until all 12 planes (PLANE01, PLANE02, ..., PLANE12) are initialized, all inside the function PlaneConfigInit. This works perfectly in debug but not in release. The initialization of PLANE01 is done without crashing but when it comes to PLANE02 it crashes at update() function of the class where I have used push_back() function.

I hope I have explained my problem well. Please let me know if more info is needed.

I would be grateful for any help.

Ahmad

Crashes which only occur in Release mode are almost always due to uninitialized memory.

What are the FileIndexStart, FileIndexStep and FilIndexEnd set to when calling the function for PLANE02? Also, can you check how many times the push_back is actually called before crashing? (For example by using a std::cout<<(i - ListStart)<<std::endl; inside the loop)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM