omnet中的导航层次错误:模拟以退出代码:139终止

Navigation hierarchy error in omnet: Simulation terminated with exit code: 139

本文关键字:退出 代码 终止 模拟 omnet 导航 层次 错误      更新时间:2023-10-16

我正在尝试使用以下代码导航到2级模块:-

cModule* parentmod = getParentModule();
cModule* grantParentmod = parentmod->getParentModule();
for (cSubModIterator iter(*grantParentmod); !iter.end();iter++)
    EV<<"Current module is "<< iter()->getFullName() <<endl;

输出为:-

Current module is notificationBoard
Current module is mobility
Current module is udpApp[0]
Current module is udpApp[1]
Current module is udp
Current module is networkLayer
Current module is routingTable
Current module is interfaceTable
Current module is wlan[0]

但是,当我直接尝试通过以下代码访问udpApp[0]时:-

cModule* parentmod = getParentModule();
cModule* grantParentmod = parentmod->getParentModule();
cModule* udpmod = parentmod->getParentModule()->getSubmodule("udpApp[0]");
EV<<"Current module is "<< udpmod->getFullName() <<endl;

仿真在运行时结束,出现以下错误:仿真终止,exit code: 139,这意味着有分段错误。但是,如果我使用任何其他模块,如'mobility'而不是'udpApp[0]',那么它可以正常工作。

谁能帮我想出一个可能的方法来解决这个问题?

你得到这个错误,因为你试图解引用一个空指针。你得到一个空指针,因为模块名称"xyz[123]"给getSubmodule不存在。它不存在,因为方括号中的数字不是子模块名称的一部分,而是它在模块向量中的索引。名称和索引必须在调用getSubmodule时分别指定。

相关文章: