title: Omnet++ A cRuntimeError exception is about to be thrown std::length_error: basic_string::_M_create
body: <p>so I get this error when i run my code</p>
  
  <blockquote>
    <p> Error in module (TraCIDemoRSU11p) RSUExampleScenario.rsu[0].appl (id=8) at event #4000, t=45.40151998544: std::length_error: basic_string::_M_create.
    TRAPPING on the exception above, due to a debug-on-errors=true configuration option. Is your debugger ready?</p>
  </blockquote>
  
  <p>it shows that I have this issue at this line after looping multiple times</p>
  
  <pre><code> VehTD = *iteh2;
  </code></pre>
  
  <p>please be informed that I'm trying to remove from this vehicle list to another vehicle list and delete the moved items.</p>
  
  <pre><code> std::list&lt;std::pair&lt;std::string,std::string&gt;&gt;::const_iterator iteh2 = waitingList.begin();
        for (std::list&lt;std::pair&lt;std::string,std::string&gt;&gt;::const_iterator iteh = waitingList.begin(); iteh != waitingList.end() &amp;&amp; !waitingList.empty(); ){
            iteh2 = iteh;
            cout&lt;&lt;"Veh ID TF 1:";
            cout&lt;&lt;VehTD.first&lt;&lt;endl;
            cout&lt;&lt;VehTD.second&lt;&lt;endl;
            VehTD = *iteh2;
            cout&lt;&lt;"Veh ID TF 2:";
            cout&lt;&lt;VehTD.first&lt;&lt;endl;
            cout&lt;&lt;VehTD.second&lt;&lt;endl;
            CompareResult3 = Locks(Locked,VehTD.second);
            if(CompareResult3.second == 1 || CompareResult3.second == 2 ){
             //remove from waiting and add to crossing
                std::string ehk = "";
                simtime_t VehicleT = simTime();
                std::pair&lt;std::pair&lt;std::string, std::string&gt;, simtime_t&gt; VehicleWithTime;
                crossingList.push_back(VehTD);
  
  
                iteh2 = waitingList.erase(iteh2);
                }
                else{
                    ++iteh;
                }
         }
     }
  </code></pre>
  
  <p>I'm using Oment++ 5.0 and veins 4.4</p>
  
  <p>I put a try and catch at this function, and it seems that the exception happens towards the end of the list.</p>
  
  <p>Update:
  I have this output:</p>
  
  <pre><code>WCounter 1
  WCounter 2
  Moving from waiting list Timer Function Exception
  WCounter 1
  WCounter 2
  WCounter 3
  Moving from waiting list Timer Function Exception
  WCounter 1
  WCounter 2
  Moving from waiting list Timer Function Exception
  </code></pre>
  
  <p>The WCounter is a variable to show how many times it looped before having the exception at the point explained earlier.</p>
  
  <p>based on request I added the locks function:  </p>
  
  <pre><code>  std::pair&lt;std::list&lt;std::string&gt;,int&gt; TraCIDemoRSU11p::Locks(std::list&lt;std::string&gt; alreadyLocked, std::string laneNo){
      bool debugL;
      //create variables for the lanes for easier use
  try{
        debugL = false;
        zero = "171270266#0_0";
        one = "171270266#0_1";
        two = "-171270025#1_0";
        three = "-171270025#1_1";
        four = "-171270266#1_0";
        five = "-171270266#1_1";
        six = "171270025#0_0";
        seven = "171270025#0_1";
  
  
  
        //create lists of locks
  
        Locks0 = Locks1 = Locks2 = Locks3 = Locks4 = Locks5 = Locks6 = Locks7 = RequestToLock = {};
        CounterOfSimilarLanes = 0;
  
        //set of 0 ,Locks0;
        Locks0.push_back(zero);
        Locks0.push_back(five);
        Locks0.push_back(seven);
        //set of 1 ,Locks1;
        Locks1.push_back(one);
        Locks1.push_back(three);
        Locks1.push_back(six);
        //set of 2 ,Locks2;
        Locks2.push_back(one);
        Locks2.push_back(two);
        Locks2.push_back(seven);
        //set of 3 ,Locks3;
        Locks3.push_back(zero);
        Locks3.push_back(three);
        Locks3.push_back(five);
        //set of 4 ,Locks4;
        Locks4.push_back(one);
        Locks4.push_back(three);
        Locks4.push_back(four);
        //set of 5 ,Locks5;
        Locks5.push_back(two);
        Locks5.push_back(five);
        Locks5.push_back(seven);
        //set of 6 ,Locks6;
        Locks6.push_back(three);
        Locks6.push_back(five);
        Locks6.push_back(six);
        //set of 7 ,Locks7;
        Locks7.push_back(one);
        Locks7.push_back(four);
        Locks7.push_back(seven);
        //This is the request to lock from the vehicle using its lane number
        if (laneNo == zero ){
            RequestToLock.insert(RequestToLock.end(),Locks0.begin(),Locks0.end());
        }else if (laneNo == one){
            RequestToLock.insert(RequestToLock.end(),Locks1.begin(),Locks1.end()) ;
        }else if (laneNo == two){
            RequestToLock.insert(RequestToLock.end(),Locks2.begin(),Locks2.end()) ;
        }else if (laneNo == three){
            RequestToLock.insert(RequestToLock.end(),Locks3.begin(),Locks3.end()) ;
        }else if (laneNo == four){
            RequestToLock.insert(RequestToLock.end(),Locks4.begin(),Locks4.end()) ;
        }else if (laneNo == five){
            RequestToLock.insert(RequestToLock.end(),Locks5.begin(),Locks5.end()) ;
        }else if (laneNo == six){
            RequestToLock.insert(RequestToLock.end(),Locks6.begin(),Locks6.end()) ;
        }else if (laneNo == seven){
            RequestToLock.insert(RequestToLock.end(),Locks7.begin(),Locks7.end()) ;
        }
  
  }   //if the already locked from the controller is empty so we take the requested lock
  catch(const std::exception &amp;e){
      cout&lt;&lt;"Preparing Locks Algorithm Exception"&lt;&lt;endl;
  }
  try{
      if (alreadyLocked.empty()){
  
            markOfLocks = 0;
            alreadyLocked.insert(alreadyLocked.end(),RequestToLock.begin(),RequestToLock.end()) ;
            Locked.insert(Locked.end(),RequestToLock.begin(),RequestToLock.end()) ;
            if (debugL == true){
                cout&lt;&lt;"First Lock in the locking algorithm"&lt;&lt;endl;
              //  dumplistLock(Locked);
            }
            ReturnOfLocks = make_pair(alreadyLocked,markOfLocks);
  
        }else{ // if the already locked by the controller isnt empty, so we need to compare the request with it
            //Search for similar items in the 2 lists
            for(std::list&lt;std::string&gt;::/*const_*/iterator it_1 = alreadyLocked.begin();it_1 != alreadyLocked.end();)
            {
                for(std::list&lt;std::string&gt;::/*const_*/iterator it_2 = RequestToLock.begin(); it_2 != RequestToLock.end();)
                {
                    if(*it_1 == *it_2)
                    {
                        ++CounterOfSimilarLanes;
                    }
  
                    ++it_2;
  
                }
                    ++it_1;
            }
  
  
            if (RequestToLock == alreadyLocked){
                markOfLocks = 1;
                Locked.clear();
                Locked = {};
                Locked.insert(Locked.end(),alreadyLocked.begin(),alreadyLocked.end()) ;
                if (debugL == true){
                    cout&lt;&lt;"Same Lane"&lt;&lt;endl;
                    dumplistLock(Locked);
                }
                ReturnOfLocks = make_pair(alreadyLocked,markOfLocks);
  
            }else if(CounterOfSimilarLanes == 0){ //if the request is concurrent meaning totally different locks
                markOfLocks = 2;
                //alreadyLocked.insert(alreadyLocked.end(),RequestToLock.begin(),RequestToLock.end()) ;
                Locked.clear();
                Locked = {};
                Locked.insert(Locked.end(),alreadyLocked.begin(),alreadyLocked.end()) ;
                if (debugL == true){
                    cout&lt;&lt;"Concurrent Lane"&lt;&lt;endl;
                    dumplistLock(Locked);
                }
  
            }else if(CounterOfSimilarLanes == 1  ||  CounterOfSimilarLanes == 2){ // if there's a similarity is 1 lock at least so it leads to conflict
                markOfLocks = 3;
                Locked.clear();
                Locked = {};
                Locked.insert(Locked.end(),alreadyLocked.begin(),alreadyLocked.end()) ;
                if (debugL == true){
                    cout&lt;&lt; "opposite Lane"&lt;&lt;endl;
                    dumplistLock(Locked);
                }
                ReturnOfLocks = make_pair(alreadyLocked,markOfLocks);
            }else{
                markOfLocks = 1;
                Locked.clear();
                Locked.insert(Locked.end(),alreadyLocked.begin(),alreadyLocked.end()) ;
                if (debugL == true){
                    cout&lt;&lt;"default case"&lt;&lt;endl;
                    dumplistLock(Locked);
                }
                ReturnOfLocks = make_pair(alreadyLocked,markOfLocks);
           }
  
        }
  }catch(const std::exception &amp;e){
      cout&lt;&lt;"Lock Cases Exceptions"&lt;&lt;endl;
  }
  
  try{
        return ReturnOfLocks;
  }catch(const std::exception &amp;e){
      cout&lt;&lt;"No Return of Locks in Locks Alg Exception"&lt;&lt;endl;
  }
  
  }
  </code></pre>