exception after setCompleteRedYellowGreenDef in sumo client c++ - c++

I was trying to build up on the example sumo client server in c++ as in the link
http://sumo.dlr.de/wiki/TraCI/C%2B%2BTraCIAPI
I wrote a function to build a complete RedYellowGreenDef as in the function below:
std::vector<libsumo::TraCILogic> Client::buildCompletetrafficLogics(std::string tlID, int phaseIndex, int increaseVal)
{
std::vector<libsumo::TraCILogic> logics = trafficlights.getCompleteRedYellowGreenDefinition(tlID);
for (int i = 0; i < (int)logics.size(); ++i)
{
for (int j = 0; j < (int)logics[i].phases.size(); ++j)
{
if (logics[i].currentPhaseIndex = phaseIndex)
{
logics[i].phases[j].duration = logics[i].phases[j].duration + increaseVal; //increase duration by 5 seconds
logics[i].phases[j].duration2 = logics[i].phases[j].duration2+ increaseVal;
}
}
}
return logics;
}
I called this function in the main function as follows:
//increase duration of phase with index "PhaseIndex" by 5000ms
std::vector<libsumo::TraCILogic> logics = client.buildCompletetrafficLogics(*tlIt, phaseIndex,5000);
libsumo::TraCILogic logic = logics[0];
client.trafficlights.setCompleteRedYellowGreenDefinition(tlID, logic);
where tlID is a valid traffic light id, but I faced The following exception when I passed the built logic to setCompleteRedYellowGreenDefinition():
terminate called after throwing an instance of 'std::invalid_argument'
what(): Storage::writeUnsignedByte(): Invalid value, not in [0, 255]
Aborted (core dumped)
Could you help me to find the problem: why I got this exception and how to tackle it?

Related

Exception thrown with OpenCV's SVM training, c++

I have a problem with the Support Vector Machine , coding with visual studio, c++.
Tried to replicate the example of the tutorial at the following link
https://docs.opencv.org/3.4.0/d1/d73/tutorial_introduction_to_svm.html and the situation is
(having a breakpoint at "return 0;" line)
1) In debug , x64 I run the solution, and after "return 0" statement I have an exception thrown
at memory location (not unhandled, luckily) and then the program exit correctly.
2) In release, x64, I run the solution, and after "return 0" statement I have an exception thrown
at memory location but clicking on "continue" button, this appears (of mat.inl.hpp)
inline
void Mat::release()
{
if( u && CV_XADD(&u->refcount, -1) == 1 )
deallocate();
u = NULL;
datastart = dataend = datalimit = data = 0;
for(int i = 0; i < dims; i++)
----> size.p[i] = 0; <----- // (that's the exact line)!
#ifdef _DEBUG
flags = MAGIC_VAL;
dims = rows = cols = 0;
if(step.p != step.buf)
{
fastFree(step.p);
step.p = step.buf;
size.p = &rows;
}
#endif
}
And I have the correct exit of the program only clicking on "continue" bottom several times.
This happens only in release mode.
How to fix it?

Why do I get this C++ error (terminate called after throwing an instance of 'std::bad_alloc') when I am playing the code?

I wrote the code pasted below to perform a method that starts monotrack and generates tracks.
void KalmanTracker::TrackInitiation(AssignData *track_, vector<int> *CT_order_, Camera *cam)
{
vector<int> CT_order= *CT_order_;
Functions f;
double T,X_MAX,X_MIN,Y_MAX,Y_MIN;
int numtracks = 0;
for(int curr_p=0; curr_p<track_->num_DTBP; curr_p++) { //plot in the current frame
if(track_->Data_TBP.at(curr_p).Free == false) {
for(int ant_p=0; ant_p<track_->num_DANT; ant_p++) { //plot in the previous frame
T = track_->Data_TBP.at(curr_p).Dato.t_obt - track_->Data_ANT.at(ant_p).Dato.t_obt;
X_MAX = track_->Data_ANT.at(ant_p).Dato.Est_PosXY.at(Xx) + MAX_SPEED*T + 3.0*sqrt(2.0*RX);
X_MIN = track_->Data_ANT.at(ant_p).Dato.Est_PosXY.at(Xx) - MAX_SPEED*T - 3.0*sqrt(2.0*RX);
Y_MAX = track_->Data_ANT.at(ant_p).Dato.Est_PosXY.at(Yy) + MAX_SPEED*T + 3.0*sqrt(2.0*RY);
Y_MIN = track_->Data_ANT.at(ant_p).Dato.Est_PosXY.at(Yy) - MAX_SPEED*T - 3.0*sqrt(2.0*RY);
if((track_->Data_TBP.at(curr_p).Dato.Est_PosXY.at(Xx) < X_MAX) && (track_->Data_TBP.at(curr_p).Dato.Est_PosXY.at(Xx) > X_MIN) &&
(track_->Data_TBP.at(curr_p).Dato.Est_PosXY.at(Yy) < Y_MAX) && (track_->Data_TBP.at(curr_p).Dato.Est_PosXY.at(Yy) > Y_MIN)) {
if((track_->Data_TBP.at(curr_p).Dato.Area > 10) && (track_->Data_ANT.at(ant_p).Dato.Area > 10) &&
(track_->Data_TBP.at(curr_p).Dato.InBox == false) && (track_->Data_ANT.at(ant_p).Dato.InBox == false)) {
f.InitiateMonotrack(track_,track_->Data_ANT.at(ant_p).Dato,track_->Data_TBP.at(curr_p).Dato,&CT_order,numtracks); //Start the monotrack
numtracks++;
track_->Data_TBP.at(curr_p).Free = true;
}
}
}
}
}
// Reordering and saving CT_order
int num_non_discarded = 0;
for(int i=0; i<track_->num_CT+numtracks; i++) {
if (CT_order.at(i) != -1) {
CT_order.at(num_non_discarded) = CT_order.at(i);
num_non_discarded++;
}
}
track_->num_CT = min(num_non_discarded,MAX_CT-1);
// Copy CT_order to the CT_order of the track
for(int i=0; i<track_->num_CT; i++)
track_->CT_order.at(i) = CT_order.at(i);
// Releasing previous plots
int num_ANT = 0;
for(int i=0; i<track_->num_DANT; i++)
track_->Data_ANT.at(i).Free = true;
// Copy the current plot to previous plot
for(int curr_p=0; curr_p<track_->num_DTBP; curr_p++) {
if (track_->Data_TBP.at(curr_p).Free == false) {
track_->Data_ANT.at(num_ANT).Dato.t_obt = track_->Data_TBP.at(curr_p).Dato.t_obt;
track_->Data_ANT.at(num_ANT).Dato.Est_PosXY.resize(2);
track_->Data_ANT.at(num_ANT).Dato.Est_PosXY.at(Xx) = track_->Data_TBP.at(curr_p).Dato.Est_PosXY.at(Xx);
track_->Data_ANT.at(num_ANT).Dato.Est_PosXY.at(Yy) = track_->Data_TBP.at(curr_p).Dato.Est_PosXY.at(Yy);
track_->Data_ANT.at(num_ANT).Dato.Area = track_->Data_TBP.at(curr_p).Dato.Area;
track_->Data_ANT.at(num_ANT).Dato.InBox = track_->Data_TBP.at(curr_p).Dato.InBox;
track_->Data_TBP.at(curr_p).Dato.image.copyTo(track_->Data_ANT.at(num_ANT).Dato.image);
track_->Data_ANT.at(num_ANT).Free = false;
num_ANT++;
}
}
track_->num_DANT = min(num_ANT,MAX_DTBP-1);
// Releasing current plots
for(int curr_p=0; curr_p<track_->num_DTBP; curr_p++)
track_->Data_TBP.at(curr_p).Free = true;
track_->num_DTBP = 0;
*CT_order_= CT_order;
}
When I execute the .cpp file I keep getting the error message:
terminate called after throwing an instance of 'std::bad_alloc'
terminate called recursively
what(): std::bad_alloc
I have gathered this has to do with a memory shortage or variables falling out of the main() function, but I can not figure out how to address the problem in this specific situation. If it is relevant, I am working on a Linux computer, programming in eclipse, using C++ language and opencv and boost libraries, because my project has two threads.
[EDIT] The debugger tells me:
Can't find a source file at "/build/glibc-t3gR2i/glibc-2.23/signal/../sysdeps/unix/sysv/‌​linux/raise.c" Locate the file or edit the source lookup path to include its location.
And the source not found is __GI_raise() at raise.c.
And after that error, the console tells me:
[xcb] Unknown sequence number while processing reply
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that. dronesNuevo: ../../src/xcb_io.c:635: _XReply: Assertion `!xcb_xlib_threads_sequence_lost' failed.
But other times the debugger tells me:
Thread 3 received signal SIGSEGV, Segmentation fault.
[Cambiando a Thread 0x7fffe1f69700 (LWP 17536)] 1574 ../sysdeps/x86_64/multiarch/memcpy-ssse3-back.S: No existe el archivo o el directorio.
__memmove_ssse3_back () at ../sysdeps/x86_64/multiarch/memcpy-ssse3-back.S:1574
and:
Can't find a source file at "/build/glibc-t3gR2i/glibc-2.23/string/../sysdeps/x86_64/mul‌​tiarch/memcpy-ssse3-‌​back.S"
Locate the file or edit the source lookup path to include its location.
Being the source not found __memmove_ssse3_back() at memcpy-sse3-back.S
The backtrace that I get:
*** Error in `path': double free or corruption (!prev): 0x00007fffa007ecb0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7ffff5e577e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x7fe0a)[0x7ffff5e5fe0a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7ffff5e6398c]
path[0x40d3b6]
path[0x40cc26]
path[0x40bd78]
path[0x40b3a2]
path[0x409f3f]
path[0x40813b]
path[0x412bd7]
path[0x43df93]
path[0x44826b]
path[0x447f38]
path[0x447ac2]
/usr/lib/x86_64-linux-gnu/libboost_thread.so.1.58.0(+0x115d5)[0x7ffff6a5b5d5]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7ffff59b06ba]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7ffff5ee682d]

Memory Error using lambda function with array

const int bookBoatNum = 10;
Wt::WPushButton *buttonBookBoat[bookBoatNum];
Wt::WDialog *dialogBookBoat[bookBoatNum];
for (int i = 1; i < bookBoatNum; i++){
dialogBookBoat[i] = new Wt::WDialog("Book Boat");
buttonBookBoat[i] = new Wt::WPushButton();
buttonBookBoat[i]->clicked().connect(std::bind([&dialogBookBoat,i]() {
dialogBookBoat[i]->show();
}));
}
The program compiles and runs. When I click on a WPushButton object, it crashes because of the third last line because of a memory error. This code works perfectly if buttonBookBoat and dialogBookBoat are single objects, rather than an array of objects. show() is a method that displays the dialog object.
Any help is appreciated, this error has been driving me crazy and my life is on the line with this code (not really).
const int bookBoatNum = 10;
Wt::WPushButton *buttonBookBoat[bookBoatNum];
Wt::WDialog *dialogBookBoat[bookBoatNum];
for (int i = 1; i < bookBoatNum; i++){
dialogBookBoat[i] = new Wt::WDialog("Book Boat");
Wt::WDialog * tempDialog=new Wt::WPushButton();
buttonBookBoat[i] = tempDialog;
buttonBookBoat[i]->clicked().connect(std::bind([tempDialog]() {
tempDialog->show();
}));
}
I think dialogBookBoat is an array so it will not exist after the function call.

terminate called after throwing an instance of std::bad_alloc

I am facing the current error since last few days and fighting with it to resolve the problem but all in vain. I am using Pythia8 and fastjet event generator together and running my simple code. Code compiled nicely but causes run time error as shown below. It runs fine with low events but for large iterations(events) it failed and print the error under discussion:
PYTHIA Warning in SpaceShower::pT2nextQCD: weight above unity
PYTHIA Error in StringFragmentation::fragment: stuck in joining
PYTHIA Error in Pythia::next: hadronLevel failed; try again
PYTHIA Error in SpaceShower::pT2nearQCDthreshold: stuck in loop
PYTHIA Error in StringFragmentation::fragmentToJunction: caught in junction flavour loop
PYTHIA Warning in StringFragmentation::fragmentToJunction: bad convergence junction rest frame
PYTHIA Warning in MultipleInteractions::pTnext: weight above unity
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
here is code:
[
double Rparam = 0.4;
fastjet::Strategy strategy = fastjet::Best;
fastjet::RecombinationScheme recombScheme = fastjet::Et_scheme;
fastjet::JetDefinition *jetDef = NULL;
jetDef = new fastjet::JetDefinition(fastjet::antikt_algorithm, Rparam,
recombScheme, strategy);
// Fastjet input
std::vector <fastjet::PseudoJet> fjInputs;
//================== event selection efficiency variables ==========
int nev=0;
int passedJetCut=0;
int passedBJetCut=0;
int passedLeptonCut=0;
int passedMtaunuCut=0;
int passedMtaunubCut=0;
int passedWCut=0;
int passedTopCut=0;
int passedMetCut=0;
int njets=2;
int nbjets=1;
int ntaus=1;
double MW=80.38;
// Begin event loop. Generate event. Skip if error. List first one.
for (int iEvent = 0; iEvent < HowManyEvents; ++iEvent) {
nev++;
if(iEvent%1000==0)cout<<"Event number "<<iEvent<<endl;
// cout<<"Event number "<<iEvent<<endl;
//==================== PYTHIA ==================
if(!pythia.next())continue;
// if (iEvent<3)pythia.process.list();
if (iEvent<2)pythia.event.list();
//if (iEvent<2)event.list();
//==================== TAUOLA ==================
// Convert event record to HepMC
HepMC::GenEvent * HepMCEvt = new HepMC::GenEvent();
//Conversion needed if HepMC uses different momentum units
//than Pythia. However, requires HepMC 2.04 or higher.
HepMCEvt->use_units(HepMC::Units::GEV,HepMC::Units::MM);
ToHepMC.fill_next_event(pythia, HepMCEvt);
// if (FirstEvent)event.list();
//Beware this does not reflect tauola effect
//tauola C++ interface only affects HepMC::GenEvent which is made
// from pythia.event
//run TAUOLA on the event
TauolaHepMCEvent * t_event = new TauolaHepMCEvent(HepMCEvt);
//Since we let Pythia decay taus, we have to undecay them first.
t_event->undecayTaus();
t_event->decayTaus();
// Reset Fastjet input for each event
fjInputs.resize(0);
// Keep track of missing ET
//*******************
class IsbFromTop {
public:
bool operator()( const HepMC::GenParticle* p ) {
if ( abs(p->pdg_id()) == 5 ) return 1;
return 0;
}
};
vector<bjet> bjets;
bjets.clear();
//======================= loop over particles ========================
for(HepMC::GenEvent::particle_const_iterator p = HepMCEvt->particles_begin();
p!= HepMCEvt->particles_end(); ++p ){
int pid=(*p)->pdg_id();
double pt=(*p)->momentum().perp();
double px=(*p)->momentum().px();
double py=(*p)->momentum().py();
double pz=(*p)->momentum().pz();
double e=(*p)->momentum().e();
double eta=(*p)->momentum().eta();
double phi=(*p)->momentum().phi();
if(abs(pid)==15){
if ( (*p)->production_vertex() ) {
for ( HepMC::GenVertex::particle_iterator mother =
(*p)->production_vertex()->particles_begin(HepMC::parents);
mother!=(*p)->production_vertex()->particles_end(HepMC::parents);
++mother )
{
if(abs((*mother)->pdg_id())==24){
W2Tau=true;
}
}
}
}
// Final state only
if ((*p)->status()!=1)continue;
if(abs(pid)==11 || abs(pid)==13){
if(!FoundLepton){
hleptonet->Fill(pt);
hleptoneta->Fill(eta);
hleptonphi->Fill(phi);
pxlepton=px;
pylepton=py;
pzlepton=pz;
elepton=e;
FoundLepton=true;
}
if(pt>20. && pt<80. && fabs(eta)<1.5)
nleptons++;
}
// No neutrinos
if (abs(pid)==12 ||
abs(pid)==14 ||
abs(pid)==16){nnu++;continue;}
// Only |eta| < 5
if(fabs(eta)>5.)continue;
// Missing ET
mex -= px;
mey -= py;
// Store as input to Fastjhttps://mail.google.com/mail/u/0/?shva=1#inboxet
fjInputs.push_back(fastjet::PseudoJet (px,py,pz,e));
}//loop over particles in the event
continue.............................
thanks a lot for your help
ijaz
Sorry I don't know anything about Pythia but in c++ new Operator will return either allocated memory pointer or it will throw a bad_alloc exception.
Using try catch we can solve this issue-
Like:
while(true)
{
try
{
string s = new string(1024*1024*1024);
break;
}
catch
{
// do stuff
}
}
It will solve the crashing issue but the CPU utilization will go UP until we got the required memory.(and if CPU reach at 100% usage it will hang the system)

Throws Error "out_of_range" for "find_first_of"

I have no idea why the first codeblock is working and the second is not:
For both blocks there is:
struct Object
{
vector <string> line;
};
Object myObject;
string a = "*Nset, nset=_PickedSet2, internal, generate";
myObject.line.push_back(a);
int iPos = 0;
int iPos2 = 7;
string sRefString = ","; // So I want to find the ",".
iPos = myObject.line.at(0).find_first_of(sRefString, iPos2); //Here is the issue.
So this works just fine:
cout <<"Output: "<< myObject.line.at(0).find_first_of(sRefString, iPos2);
It gives:
Output: 23
But this does not:
iPos = myObject.line.at(0).find_first_of(sRefString, iPos2);
Here i get an error:
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
zweiterminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr
Thanks for help!