在带有静脉的Omnet ++中检查模块析构函数

时间:2016-05-31 10:50:31

标签: c++ omnet++ veins

我有一个VANET项目,我使用veins-2.0-rc2。

在LinearMobility.cc课程中我有这段代码,

void LinearMobility::initialize(int stage)
{
  BaseMobility::initialize(stage);

  debugEV << "initializing LinearMobility stage " << stage << endl;

  if (stage == 0)
  {

    move.setSpeed(par("speed").doubleValue());
    acceleration = par("acceleration");
    angle = par("angle");
    angle = fmod(angle,360);
 }
 else if(stage == 1)
 {
    stepTarget = move.getStartPos();

    if(!world->use2D()) 
    {
        opp_warning("This mobility module does not yet support 3 dimensional movement."\
                    "Movements will probably be incorrect.");
    }
    if(!world->useTorus()) 
    {
        opp_warning("You are not using a torus (parameter \"useTorus\" in"\
                    "BaseWorldUtility module) playground but this mobility"\
                    "module uses WRAP as border policy.");
    }
  }
}

我尝试通过修改LinearMobility.cc类

将事故事件添加到我的场景中
void LinearMobility::initialize(int stage)
{

  BaseMobility::initialize(stage);

  debugEV << "initializing LinearMobility stage " << stage << endl;

if (stage == 0){

    move.setSpeed(par("speed").doubleValue());
    acceleration = par("acceleration");
    angle = par("angle");
    angle = fmod(angle,360);

    accidentCount = par("accidentCount");

    WATCH(angle);

    startAccidentMsg = 0;
    stopAccidentMsg = 0;

    if (accidentCount > 0) {
                simtime_t accidentStart = par("accidentStart");
                startAccidentMsg = new cMessage("scheduledAccident");
                stopAccidentMsg = new cMessage("scheduledAccidentResolved");
                scheduleAt(simTime() + accidentStart, startAccidentMsg);
            }
}
else if(stage == 1){
    stepTarget = move.getStartPos();

    if(!world->use2D()) {
        opp_warning("This mobility module does not yet support 3 dimensional movement."\
                    "Movements will probably be incorrect.");
    }
    if(!world->useTorus()) {
        opp_warning("You are not using a torus (parameter \"useTorus\" in"\
                    "BaseWorldUtility module) playground but this mobility"\
                    "module uses WRAP as border policy.");
    }
  }
 }

void LinearMobility::handleSelfMsg(cMessage *msg)
{
   if (msg == startAccidentMsg) {

    simtime_t accidentDuration = par("accidentDuration");
    scheduleAt(simTime() + accidentDuration, stopAccidentMsg);
    accidentCount--;
  }
  else if (msg == stopAccidentMsg) {

    if (accidentCount > 0) {
        simtime_t accidentInterval = par("accidentInterval");
        scheduleAt(simTime() + accidentInterval, startAccidentMsg);
    }
 }
}

但我在OMNeT ++中有这个问题:

  

未公开的对象:(cMessage)Scenario.node [0] .mobility.scheduledAccidentResolved - check module destructor

     

未公开的对象:(cMessage)Scenario.node [0] .mobility.scheduledAccident - check module destructor

     

未公开的对象:(cMessage)Scenario.node [1] .mobility.move - 检查模块析构函数   未公开的对象:(cMessage)Scenario.node [2] .mobility.move - 检查模块析构函数   未公开的对象:(cMessage)Scenario.node [3] .mobility.move - 检查模块析构函数   未公开的对象:(cMessage)Scenario.node [4] .mobility.move - check module destructor

任何人都可以帮我解决吗?

1 个答案:

答案 0 :(得分:0)

这些消息通知您已创建对象但未删除它。它涉及消息:startAccidentMsgstopAccidentMsg以及可能与移动相关的消息 解决方案:在finish()方法内添加以下代码:

cancelAndDelete(startAccidentMsg);
cancelAndDelete(stopAccidentMsg);

如果没有finish()方法,只需添加即可。