使用 Veins 检查 Omnet++ 中的模块析构函数
check module destructor in Omnet++ with Veins
我有一个VANETs项目,我使用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.scheduledAccidentResolve -- check module destructor
未处置的对象:(cMessage) Scenario.node[0].mobility.scheduledAccident-- check module destructor
未释放的对象: (cMessage) Scenario.node[1].mobility.move -- check module 析构函数未处置的对象:(cMessage) Scenario.node[2].mobility.move -- check module destructor未处置的对象:(cMessage) Scenario.node[3].mobility.move -- check module destructor未处置的对象:(cMessage) Scenario.node[4].mobility.move -- 检查模块析构函数
谁能帮我解决?
这些消息通知您已创建对象,但不会将其删除。它涉及消息:startAccidentMsg
,stopAccidentMsg
,可能还有与移动相关的消息。
解决方案:在方法finish()
中添加以下代码:
cancelAndDelete(startAccidentMsg);
cancelAndDelete(stopAccidentMsg);
如果没有finish()
方法,只需添加它。
- 什么时候调用组成单元对象的析构函数
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 内联映射初始化的动态atexit析构函数崩溃
- 什么时候调用析构函数
- 优先顺序:智能指针和类析构函数
- C++-明确何时以及如何调用析构函数
- 使用基类指针创建对象时,缺少派生类析构函数
- 在c++中使用向量时,如何调用构造函数和析构函数
- 重载运算符new[]的行为取决于析构函数
- 我需要知道编译器如何在cpp中使用析构函数
- 为什么在使用转换构造函数赋值后调用C++类的析构函数?
- 析构函数调用
- 通过引用传递-为什么要调用这个析构函数
- 对具有动态分配的内存和析构函数的类对象的引用
- 重载 -> shared_ptr 个实例中的箭头运算符<interface>,接口中没有纯虚拟析构函数
- C++成员的析构函数顺序与shared_ptr
- C++ 防止在映射中放置()时调用析构函数
- 在这种情况下显式调用时,std::cout 如何更改析构函数的行为?
- 调用析构函数以释放动态分配的内存
- 使用 Veins 检查 Omnet++ 中的模块析构函数