0

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.

Hadeel A.
  • 19
  • 8
  • Where do you access the array? – Julian Heinovski Jul 16 '18 at 08:36
  • Is this question answered? – Julian Heinovski Jul 22 '18 at 12:30
  • no it's not answered yet. i tried to modify the find function in the onDataDelayed, and replace it with a while loop and a boolian variable it still wasn't fixed and i'm still getting the same errors. I wasn't able to answer earlier since i wasn't allowed to use any screens for sometime by the ophthalmologist. – Hadeel A. Aug 28 '18 at 12:28

3 Answers3

1

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.

Julian Heinovski
  • 1,822
  • 3
  • 16
  • 27
  • I am not sure why is trying to access it though I only have few elements in the array sent from the RSU to the vehicle. I added the code where the array is used. – Hadeel A. Jul 16 '18 at 15:31
  • Can run compile in debug mode (`make MODE=debug`) and run `./debug` instead of `./run`? I like to know where the error happens. So far I could't spot a reason for it. – Julian Heinovski Jul 16 '18 at 20:49
  • I'm not sure how to apply the command you asked me to do to show you the error when running the code. I am still kinda new in using Omnet++. is there a way to show me where to use these commands when running veins or tell me where to find the equivalent on the IDE itself. sorry for the inconvenience and thank you for your time. – Hadeel A. Jul 17 '18 at 16:07
0

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/

Hamzah
  • 120
  • 6
  • I tried your suggestion it was still giving me errors. I also made a while loop instead of the find function with a boolian variable when find the vehicle ID, and it still gave me the same error. – Hadeel A. Aug 28 '18 at 12:24
0

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

Hadeel A.
  • 19
  • 8
  • Great that you found a solution and also posted it here. Please mark the question as solved by marking this answer as accepted. This helps others even more. – Julian Heinovski Aug 31 '18 at 12:30