使用push_back std :: vector崩溃。在VS2008中

时间:2014-05-21 22:07:14

标签: c++ visual-studio-2008 fatal-error stdvector push-back

我在以下几行中定义了一个结构DutPlayerArrayElement

namespace Common
{

namespace Constants {
  const int MaxNumberOfIPAddresses = 10;
  const int NumberOFRFOutputs = 100;
  const int NumberOfPlayers = 100;
  const int SignalFileNameSize = 30;
}

enum AntennaType
{
  Omni = 0,
  Directive,
  Custom,
  InvalidAntenna
};

enum ModulationID
{
  CW = 0,
  SSB,
  LSB,
  AM,
  FM,
  WFM,
  DVBT
};

enum SigFileID
{
  SIG_FILE_ID_ARB12 = 1,
  SIG_FILE_ID_ARB16,
  SIG_FILE_ID_WAV,
  SIG_FILE_ID_TXT  
};

typedef struct
{
  //Basic
  double dLatitude;
  double dLongitude;
  double dAltitude;
  double dHeading;
  float fNorthSudVelocity;
  float fEastOvestVelocity;
  float fVerticalVelocity;
  unsigned int uiIsValid;
  bool bIsDestroyed;
  bool bTxIsOn;
  ModulationID xModulationID;
  SigFileID xSigFileType ;
  char cSigFileName[128];
  bool bLoopPlayback ;
  char cAntennaTableFile[128];
  bool bUseAntGainFactor;
  double dAntGainFactor;
  double dAntennaOrientation;
  double dCarrierFrequency;
  bool bTxIsLOS;
  double dPwr;
  double dAzimuth;
  double dElevation;
  double dDistance;
  char cEntityName[128];
  //char cModulation[2];
}PlayerArrayElement;

typedef struct 
{
  //Basic
  double dLatitude;
  double dLongitude;
  double dAltitude;
  double dHeading;
  float fNorthSudVelocity;
  float fEastOvestVelocity;
  float fVerticalVelocity;
  bool bIsDestroyed;
  unsigned int uiNumAssignedRFOut;
  bool bIsSync;
  unsigned int uiNumRFOutXIP;
  int iAssignedRFOut[Constants::NumberOFRFOutputs];

  unsigned int uiRfGenCount;
  int iIpAddress[Constants::MaxNumberOfIPAddresses];
  unsigned int xPort[10];
  double xCarrierFrequency[10];

  //AntennaType xAntennatype;
  char cAntennaTableFile[128];
  bool bUseAntGainFactor;
  double dAntGainFactor;
  double dAntennaOrientation;
  unsigned int uiNumOfPlayer; 
  PlayerArrayElement xScenarioPlayer[Constants::NumberOfPlayers];
  char cEntityName[128]; 
  unsigned int uiIsValid;
  bool simIsRunning;
} DutPlayerArrayElement;

typedef std::vector<DutPlayerArrayElement> DutPlayers;

}

我还定义了typedef std::vector<DutPlayerArrayElement> DutPlayers;

在Visual Studio 2008库中,我声明了一个以此向量作为成员的类:

class COM_API MyClass
{
public:
  SimComintManager();
  ~SimComintManager() ;

  bool init();
  void runme();


private:

  void setup();

private:

  // ....
  Common::DutPlayers m_xDutPlayers;
  // other structures...
};
runme方法中的

void MyClass::runme()
{
  while(m_bScenarioIsRunning)
  {
    if(m_uiIterationCount == 0)
    {
      m_pGen->setRfOutState(0, ON);
    }
    else
    {
      //aggiornare RF scenario in base a SHM attuale
      m_xDutPlayers.clear() ;
      m_xShmReader.getData(m_xDutPlayers) ;
    }
  }

}

ShmReader是在另一个库中定义的类,它使用定义了vector的相同.h文件:

bool Reader::getData( Common::DutPlayers& xDutVector)
{
  Common::DutPlayerArrayElement xEntityArrayElement;
  for(int i = 0; i < m_iNumberOfEntities; i++)
  {
    xEntityArrayElement = m_pxPlayerShmVector->getValue(i);
    if(xEntityArrayElement.uiIsValid == 1)
      m_bSimulationState = xEntityArrayElement.simIsRunning;
      xDutVector.push_back(xEntityArrayElement);
  }
  return true;
}

当我致电xDutVector.push_back(xEntityArrayElement);时,我发现错误并导致程序崩溃。 Visual Studio说Microsoft Visual Studio C Runtime Library has detected a fatal error in program.exe当我单击Break按钮时,callstack位于vector.h的第161行,这段代码的_SCL_SECURE_VALIDATE_RANGE行:

_Myt& operator+=(difference_type _Off)
    {   // increment by integer
    _SCL_SECURE_VALIDATE(this->_Has_container());
    _SCL_SECURE_VALIDATE_RANGE(
        _Myptr + _Off <= ((_Myvec *)(this->_Getmycont()))->_Mylast &&
        _Myptr + _Off >= ((_Myvec *)(this->_Getmycont()))->_Myfirst);
    _Myptr += _Off;
    return (*this);
    }

我已经google了一下,我发现了关于迭代器擦除的错误,但没有关于push_back的错误。我做错了什么以及如何正确使用push_back?

0 个答案:

没有答案