Search code examples
c++omnet++veins

check module destructor in Omnet++ with Veins


I have a VANETs project, I work with veins-2.0-rc2.

In class LinearMobility.cc I have this code,

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.");
    }
  }
}

I try to add the accident event to my scenario by modifying the class 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);
    }
 }
}

But I have this problem in OMNeT++ :

undisposed object: (cMessage) Scenario.node[0].mobility.scheduledAccidentResolved -- check module destructor

undisposed object: (cMessage) Scenario.node[0].mobility.scheduledAccident -- check module destructor

undisposed object: (cMessage) Scenario.node[1].mobility.move -- check module destructor undisposed object: (cMessage) Scenario.node[2].mobility.move -- check module destructor undisposed object: (cMessage) Scenario.node[3].mobility.move -- check module destructor undisposed object: (cMessage) Scenario.node[4].mobility.move -- check module destructor

Can anyone help me solve it?


Solution

  • These messages inform you that you have created an object but you do not remove it. It concerns messages: startAccidentMsg, stopAccidentMsg and probably messages connected with moving.
    Solution: inside finish() method add the following code:

    cancelAndDelete(startAccidentMsg);
    cancelAndDelete(stopAccidentMsg);
    

    If there is no finish() method, just add it.