Hadeel A.
Hadeel A.

Reputation: 19

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.

Upvotes: 0

Views: 247

Answers (3)

Hadeel A.
Hadeel A.

Reputation: 19

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. :)

Upvotes: 0

Hamzah
Hamzah

Reputation: 120

I am not sure if this is the reason for your error:

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

But, It is better to write it this way:

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

I don't recommend referencing thefind iterator (i.e., *ttry) if it is not found, it is like referencing *(vehicleList.end()).

it seems to me you have two veichleList variables, an array in the dsm and another one which is a vector. is this correct? if yes, you should make sure that the veichleList.size() is always less or equal 220.

Check this tutorial to learn how to debug your project in omnet++: https://docs.omnetpp.org/tutorials/tictoc/part2/

Upvotes: 0

Julian Heinovski
Julian Heinovski

Reputation: 1821

Even without seeing the actual code from the application (appl) or from the configuration file you are using, I am guessing you are trying to get the last element (element 220) from the array.

The error message already tells what the problem is. Your array has a size of 220 and you are trying to use the index 220 which is not possible, since array indexes start at 0. Therefore for addressing the last element in your array, you have to use index 221.

Upvotes: 1

Related Questions