3
votes

I have installed veins 4.7 and I went through the tutorial. Everything is working. Now I built a new module more like a DemoBaseApplLayer. This module inherits from BaseAppLayer. In the initialize method, I call a dispatchMsg function. which looks like the following:

Based on several answers I have introduced cancelAndDelete(msg) in the destructor and finish method. I also added the delete(msg) method but no avail

dispatchMsg() {

//SignedBSMMessage sgndBSMMsg(location);
char* inputData = signedBSMMessage.CreateBSMMessage(to_CharPtr(this->curPosition.x),
                                                        to_CharPtr(this->curPosition.y),
                                                        to_CharPtr(this->curSpeed.z ),
                                                        to_CharPtr(this->curDirection.z));
cout << "Start dispatchMsg" << endl;

ObuSigndBSM obuSigndBSM("BasicSafetyMessage", 01);
obuSigndBSM.setSignedBsm(inputData);
obuSigndBSM.setMsgLength(signedBSMMessage.getLength());
Coord pos;
traci->getRoadMapPos(pos);
string laneId = std::to_string(pos.z);
obuSigndBSM.setLandId(laneId.c_str());

 bsmMessage=&obuSigndBSM;
this->sendDown(bsmMessage);
//delete bsmMessage;
cout << "End dispatchMsg" << endl;
EV_DEBUG << "BSMApp::dispatchMsg end " ;
delete(bsmMessage);

}

However, I keep on getting this exception:

Object BasicSafetyMessage is currently in (omnetpp::cEventHeap)simulation.scheduled-events, it cannot be deleted.

If this error occurs inside omnetpp::cEventHeap, it needs to be changed to call drop() before it can delete that object.

If this error occurs inside omnetpp::cEventHeap's destructor and Basic Safety Message is a class member,

omnetpp::cEventHeap needs to call drop() in the destructor -- in module (Veins::BSMApp) OBUScenerio.node[0].appl (id=7), at t=1s, event #2

what I am missing? your kind response will be appreciated.

1

1 Answers

0
votes

After calling this->sendDown(bsmMessage) consider the pointer owned by the OMNeT++ simulation kernel. Do not call delete(bsmMessage) after calling this method - otherwise you will delete the event (think: all information about the frame you want to send) while OMNeT++ is delivering it.

Only delete pointers to data that the OMNeT++ has given to you (e.g., as an event for data having been received), that is, in the method that handles received frames.