[英]Simulating Leach has encounter a problem. Finished with error in omnet++
When running the simulation in omnet++ 5.7 the execution stops suddenly and closes.在 omnet++ 5.7 中运行模拟时,执行突然停止并关闭。 This is the code that is being run in omnet
这是在 omnet 中运行的代码
auto simulation = getSimulation();
for (i = 1; i <= simulation->getLastComponentId(); i++) {
int x, y, id;
//scan the simulation module vector
mod = (cModule*)simulation->getModule(i);
if (strcmp(mod->getName(), "node") == 0) {
id = ((Node*)mod)->myId;
x = ((Node*)mod)->xpos;
y = ((Node*)mod)->ypos;
nodePtr[id] = ((Node*)mod);
if (id != this->myId) {
cGate* g;
char gName1[32], gName2[32];
// make new gate here
if (this->hasGate(gName1)) {
this->gate(gName1)->disconnect();
this->deleteGate(gName1);
}
this->addGate(gName1, cGate::OUTPUT, false);
// make new gate at other side
if (mod->hasGate(gName2)) {
mod->gate(gName2)->disconnect();
mod->deleteGate(gName2);
}
mod->addGate(gName2, omnetpp::cGate::INPUT, false);
//CHANNEL
cIdealChannel* ch = NULL;
this->gate(gName1)->connectTo(mod->gate(gName2), ch);
g = this->gate(gName1);
g->setDisplayString(g->getDisplayString());
}
}
}
I assume that the last line g->setDisplayString(g->getDisplayString());
我假设最后一行
g->setDisplayString(g->getDisplayString());
is probably where the code breaks.可能是代码中断的地方。 The code repeats in the for loop with
i<= simulation->getLastComponentId()
.代码在 for 循环中使用
i<= simulation->getLastComponentId()
重复。 I'm new to Omnet++.我是 Omnet++ 的新手。 Any suggestion to fix this would be helpful.
任何解决此问题的建议都会有所帮助。
Thanks.谢谢。
Several things in your code may be source of crashing:代码中的几件事可能是崩溃的根源:
getModule(i)
may return nullptr
, see OMNeT++ Simulation API , so you should check in the code whether result is not nullptr
. getModule(i)
可能会返回nullptr
,请参阅OMNeT++ Simulation API ,因此您应该检查代码是否结果不是nullptr
。gName1
and gName2
are not set! gName1
和gName2
未设置! Other issues:其他事宜:
(Node*)mod
use dynamic_cast<Node*)>(mod)
and check whether results is not nullptr
.(Node*)mod
使用dynamic_cast<Node*)>(mod)
并检查结果是否不是nullptr
。strcmp(mod->getName(), "node") == 0
I advice using mod->isName("node")
- see OMNeT++ Simulation APIstrcmp(mod->getName(), "node") == 0
我建议使用mod->isName("node")
- 请参阅OMNeT++ Simulation APIgetModuleByPath()
see OMNeT++ Simulation ManualgetModuleByPath()
参见OMNeT++ Simulation Manual
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.