2016-05-31 60 views
0

我有一個VANETs項目,我使用veins-2.0-rc2工作。在靜脈Omnet ++中檢查模塊析構函數

在課堂上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 - 檢查模塊析構

未予處置目的:(cMessage派生而來)Scenario.node [0] .mobility.scheduledAccident - 檢查模塊析構

未予處置目的:(cMessage派生而來)Scenario.node [1] .mobility.move - 檢查模塊(cMessage)Scenario.node [2] .mobility.move - 檢查模塊析構函數 未配置對象:(cMessage)Scenario.node [3] .mobility.move - 檢查模塊析構函數 未配置對象:(cMessage)Scenario.node [4] .mobility.move - 檢查模塊析構函數

任何人都可以hel我解決它?

回答

0

這些消息通知您已經創建了一個對象,但不刪除它。它涉及消息:startAccidentMsgstopAccidentMsg和可能與移動相關的消息。
解決方案:內finish()方法添加以下代碼:

cancelAndDelete(startAccidentMsg); 
cancelAndDelete(stopAccidentMsg); 

如果沒有finish()方法,只是將它加入。

+0

是我在我的代碼中有finish()方法:'void LinearMobility :: finish() { statistics.stopTime = simTime(); statistics.recordScalars(* this); cancelAndDelete(startAccidentMsg); cancelAndDelete(stopAccidentMsg); // isPreInitialized = false; }'但同樣的問題發生 – Nacer

+0

我認爲你的模型還有另一個錯誤。嘗試在你的'omnetpp.ini'中設置'debug-on-errors = true'並在調試模式下運行你的模擬。 –