Peter
Peter

Reputation: 168

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

I am trying to navigate to a 2 level up module using following code:-

cModule* parentmod = getParentModule();
cModule* grantParentmod = parentmod->getParentModule();

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

And the output is:-

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]

However when I directly try to access udpApp[0] through the following code:-

cModule* parentmod = getParentModule();
cModule* grantParentmod = parentmod->getParentModule();

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

Simulation end at run time with following error: Simulation terminated with exit code: 139, which means a segmentation fault. However if I use any other module like 'mobility' instead of 'udpApp[0]' then it works fine.

Can anybody please help me to figure out a possible way to resolve this situation.

Upvotes: 2

Views: 1888

Answers (1)

Christoph Sommer
Christoph Sommer

Reputation: 6943

You are getting this error because you are trying to dereference a Null pointer. You are getting a Null pointer because the module name "xyz[123]" given to getSubmodule does not exist. It does not exist because the number in square brackets is not part of the submodule name, but its index in the module vector. Name and index have to be specified separately in the call to getSubmodule.

Upvotes: 1

Related Questions