Search code examples
omnet++veins

Omnet++, A cRuntimeError exception is about to be thrown


I'm currently using Omnet++, and veins, and I have this runtime error appearing suddenly, and I am not able to understand it in order to fix it properly.

Error in module (TraCIDemoRSU11p) RSUExampleScenario.rsu[0].appl (id=8) at event #6180, t=53.956510612297: Array of size 220 indexed by 220. TRAPPING on the exception above, due to a debug-on-errors=true configuration option. Is your debugger ready?

I am assuming that it might be related to this message I am sending from the RSU to the vehicles with this code, but I am not sure how it's related.

cplusplus {{
#include "veins/modules/messages/WaveShortMessage_m.h"

}}
class WaveShortMessage;


message DelayedFromControllerMessage extends WaveShortMessage {
    string vehiclesList [220] ;

}

I am using omnet++ Version: 5.0 and Veins 4.4

Edited, I'm using the array in these places:

1-

void TraCIDemoRSU11p::sendDelayedMessage(std::list<const char *> vehicleList) {
    sentDelayedMessage = true;
    //vehicleList = {};
    t_channel channel = dataOnSch ? type_SCH : type_CCH;
    DelayedFromControllerMessage* dsm = prepareDelayedSM("delayed",dataLengthBits, channel, dataPriority, -1,2,vehicleList);

    std::list<const char *>::iterator it = vehicleList.begin();
    //const char * v;
    char* vx = new char [100];
    vx[0] = '\0';
    for(int i=0; i<vehicleList.size(); i++){
        //v =*it;
        strcpy(vx,*it);
        //vx = *it;
        ++it;
        dsm->setVehiclesList(i, vx);
     }
    if (sendDelayedEvt->isScheduled()) {
        cancelAndDelete(sendDelayedEvt);
    }else {
        delete sendDelayedEvt;
    }
    sendDelayedEvt = new cMessage("delayed evt", SEND_DELAYED_EVT); // create event object to use it in timing

    simtime_t offSet = dblrand() * (par("beaconInterval").doubleValue());
    TimeStart = simTime() + offSet;
    scheduleAt(TimeStart, sendDelayedEvt);
    sendDelayedSM(dsm);

}

2-

DelayedFromControllerMessage*  BaseWaveApplLayer:: prepareDelayedSM(const char * name, int lengthBits, t_channel channel, int priority, int rcvId,int serial,std::list<const char *>vehicleList ) {
    DelayedFromControllerMessage* dsm =       new DelayedFromControllerMessage(name);

    dsm->addBitLength(headerLength);
    dsm->addBitLength(lengthBits);

    switch (channel) {
        case type_SCH: dsm->setChannelNumber(Channels::SCH1); break; //will be rewritten at Mac1609_4 to actual Service Channel. This is just so no controlInfo is needed
        case type_CCH: dsm->setChannelNumber(Channels::CCH); break;
    }

    dsm->setPsid(0);
    dsm->setPriority(priority);
    dsm->setWsmVersion(1);
    dsm->setTimestamp(simTime());
    dsm->setSenderAddress(myId);
    dsm->setRecipientAddress(rcvId);
    dsm->setSenderPos(curPosition);
    dsm->setSerial(serial);



    std::list<const char *>::iterator it = vehicleList.begin();
    const char * v;

       for(int i=0; i<vehicleList.size(); i++){
           v =*it;
           ++it;
           VLvar1.push_back(v);
           dsm->setVehiclesList(i, v);
       }



    if ((std::string)name == "beacon") {
        DBG << "Creating Beacon with Priority " << priority << " at Applayer at " << dsm->getTimestamp() << std::endl;
    }
    if ((std::string)name == "delayed") {
        DBG << "Creating Data with Priority " << priority << " at Applayer at " << dsm->getTimestamp() << std::endl;
    }

    return dsm;
}

3-

void MyTraCIDemo11p::onDataDelayed(DelayedFromControllerMessage* dsm) {
    int x = 0;
    std::string vehichleId = mobility->getExternalId();

        for (int i=0 ; i < dsm->getVehiclesListArraySize();i++)
        {
            vehicleList.push_back(std::string(dsm->getVehiclesList(i)));

        }


        ttry = std::find(vehicleList.begin(), vehicleList.end(), vehichleId);
        if (vehichleId == *ttry){
            x = 1;
        }


        if (state == QUEUING  && x == 1){
            findHost()->bubble("Received ");
             state = WAITING;
             stateToString(state);
        }
}

The message should be sent from the RSU to the vehicles.


Solution

  • So i ended up finding a solution for this issue just now.

    it was by doing this:

    cplusplus {{
    #include "veins/modules/messages/WaveShortMessage_m.h"
    
    }}
    class WaveShortMessage;
    
    
    message DelayedFromControllerMessage extends WaveShortMessage {
        string vehiclesList [] ;
    
    }
    

    =====

    DelayedFromControllerMessage*  BaseWaveApplLayer:: prepareDelayedSM(const char * name, int lengthBits, t_channel channel, int priority, int rcvId,int serial,std::list<const char *>vehicleList ) {
    DelayedFromControllerMessage* dsm =       new DelayedFromControllerMessage(name);
    
    dsm->addBitLength(headerLength);
    dsm->addBitLength(lengthBits);
    
    switch (channel) {
        case type_SCH: dsm->setChannelNumber(Channels::SCH1); break; //will be rewritten at Mac1609_4 to actual Service Channel. This is just so no controlInfo is needed
        case type_CCH: dsm->setChannelNumber(Channels::CCH); break;
    }
    
    dsm->setPsid(0);
    dsm->setPriority(priority);
    dsm->setWsmVersion(1);
    dsm->setTimestamp(simTime());
    dsm->setSenderAddress(myId);
    dsm->setRecipientAddress(rcvId);
    dsm->setSenderPos(curPosition);
    dsm->setSerial(serial);
    
    
    int NS = 0;
    std::list<const char *>::iterator itPD = vehicleList.begin();
    const char * vPD;
    int i0 = 0;
    while(itPD != vehicleList.end()){
        vPD = *itPD;
        ++itPD;
        ++NS;
        dsm->setVehiclesListArraySize(NS);
        dsm->setVehiclesList(i0, vPD);
        ++i0;
        VLvar1.push_back(vPD);
    
    }
    
    if ((std::string)name == "beacon") {
        DBG << "Creating Beacon with Priority " << priority << " at Applayer at " << dsm->getTimestamp() << std::endl;
    }
    if ((std::string)name == "delayed") {
        DBG << "Creating Data with Priority " << priority << " at Applayer at " << dsm->getTimestamp() << std::endl;
    }
    
    return dsm;
    }
    

    I removed the array size and placed with a manual counter in BaseWaveApplLayer:: prepareDelayedSM using a while loop. I thought about posting the solution to help others when facing a similar problem. :)