I got this error when running my code and when I do. my brain doesn’t respond at all. I am using like 1000 len vectors for some path planning stuff im trying but im not sure what this is. (also nothing is connected on port one)
Please post your code so the people on this forum can help you
uhhh ok good luck tho its kinda complex…this is the function the error happens on. I am SAMPLE_COUNT = 1000.
std::vector<splineConfig> parametrize(std::vector<CoefficientList> coeffs) {
std::vector<splineConfig> splinePoints;
double tStep = 1/SAMPLE_COUNT;
double arcLength = 0;
distanceParametrized.push_back({0,WaypointList[0].x,WaypointList[0].y,cos(WaypointList[0].angle),sin(WaypointList[0].angle),0,0});
splinePoints.push_back({0,WaypointList[0].x,WaypointList[0].y,cos(WaypointList[0].angle),sin(WaypointList[0].angle),0,0});
for(int i = 1; i<SAMPLE_COUNT; i++) {
splineConfig dataPoint = getVectors(i/SAMPLE_COUNT,coeffs);
arcLength +=sqrt(dataPoint.dx*dataPoint.dx + dataPoint.dy*dataPoint.dy)/SAMPLE_COUNT;
//std::cout << arcLength << std::endl;
dataPoint.lengthProgress = arcLength;
splinePoints.push_back(dataPoint);
}
splineConfig endpoint = getVectors(.999, coeffs);
double dsMax = endpoint.lengthProgress*.01;
int skipper = 0;
for(int i = 1; i <SAMPLE_COUNT-2;i = i + 1) {
//double ds = splinePoints[i+1].lengthProgress-splinePoints[i].lengthProgress;
int j = 1;
double currDistanceSegment =0;
splineConfig upper;
splineConfig lower;
/*while(currDistanceSegment < dsMax) {
upper = splinePoints[i+j];
lower = splinePoints[i];
double ds = upper.lengthProgress-lower.lengthProgress;
currDistanceSegment += ds;
j++;
}
j = skipper;*/
upper = splinePoints[i+1];
lower = splinePoints[i];
double ds = upper.lengthProgress-lower.lengthProgress;
if (ds < dsMax) {
splinePoints.erase(splinePoints.begin() +i +1);
}
}
// std::cout << splinePoints[500].lengthProgress <<std::endl;
return(splinePoints);
}
probably stack overflow.
are you in PROS or VEXcode ?
VEXcode (20 characters)
yea, so you only have an 8 k stack to work with, if that big vector ends up on the stack you will probably overflow. Either make it global or dynamically allocate it, see if that fixes the issue.
(we are actually going to change the way stacks work in the next vexos, low number of threads will have much more stack to play with)
yea I did make it global and I got this error: But ill try to dynamically allocate it:
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
well, maybe if it’s really big you will need to increase heap size. see this post, it explains how to make heap larger.
user programs have 72MB to play with, but we usually leave the heap fairly small as most users will not be using it.
Didn’t seem to work unfortunately. Do you know what exactly the error means?
Several observations.
First of all, you didn’t provide the rest of the code with global variables and other functions, that could very well be the source of error.
Second, assuming SAMPLE_COUNT is integer, i/SAMPLE_COUNT will always be 0. Similarly tStep is 0, although it is unused.
Finally, you are pushing into splinePoints vector SAMPLE_COUNT-1=999 elements from [0] to [998], and trying to access them as [1] to [998].
However, each call to splinePoints.erase() will reduce vector size by 1, thus you may endup accessing and erasing elements beyond vector end. Do not increment iterator after you call erase.
I believe, your code could be significantly simplified.
Thanks for the help guys! So turns out it wasn’t about stack overflow at all it was a seg fault as @weilin predicted . For some reason that error didn’t show up on the v5 terminal and returned this really weird error but it did on an online cpp complier.
We don’t really have the concept of a seg fault on the V5, embedded systems don’t work in the same way as a desktop computer with windows/unix etc. When memory get corrupted behavior can be unpredictable, the “NXB” error was probably “NXP” which is referring to the small external cpu we have that controls power inside the V5, perhaps communication was lost between vexos and that device. Anyway, glad you solved the issue.