terminate called after throwing an instance of ‘char const*’
Hello everyone,
I am not that new to coding; but definitely new to coding in C++ so I have a feeling this may be related to my improper use of C++ and OpenFrameworks. I am kind of stuck as when this error happens the whole app just closes … no beachball, freezing, or anything else - just closes. I am bringing together Zach’s Vector Field code and RUI’s optical Flow ( and later some sound libraries ) to create a music visualizer for a friend doing a cello performance. I’ll list my specs and some of the “testApp.cpp” code below.
Machine: MBP 2.4
IDE: xCode
I noticed this problem only became apparent once I started wrapping some code (originally in update) into a function that scans along a certain part of the screen to look for vector field movement. This is it below. It is called from update and I wonder if maybe the problem may be related to creating a new “vector” array every time it is called … maybe my lack of real understandng of pointers and the like is messing it up?
Thanks in advance for any help! (I’d add the project folder but it is about 100mb)
//now loop through screen to find where motion is occuring
inline vector <int> application::returnMotionXValues( ofxVec2f topLeftCorner, ofxVec2f bottomRightCorner, float threshold, int beginX, int endX)
{
//first we will set a virtual bounding box proportional to width raindropfall width given then move that across across screen to find where particles should fall
magTot = 0; //total magnitudes of all vectors - this will determine if it should rain there or not
int boxWidth = bottomRightCorner.x - topLeftCorner.x;
vector <int> xResArr;
//set up arr
for(int i = 0; i < endX; i++)
{
xResArr.push_back(0);
}
//scan across screen
for(counterX = beginX; counterX < endX; counterX += boxWidth)
{
//set corners of bounding box
topLeftCorner.set(counterX, topLeftCorner.y);
bottomRightCorner.set(counterX + boxWidth, bottomRightCorner.y);
magTot = returnVecMagsOfBox(topLeftCorner, bottomRightCorner);
if (magTot > threshold)
{
xResArr = addRandomMotionXBoundary(counterX, boxWidth, xResArr);
}
}
return xResArr;
}
inline float application::returnVecMagsOfBox(ofxVec2f leftHandCorner, ofxVec2f botRightCorner)
{
float totalMag = 0.0f;
ofxVec2f currVec;
int arrSize = VF.field.size();
for(int i = 0; i < arrSize ; i++)
{
currVec = returnVecConcenPoint(i);
if((currVec.x >= leftHandCorner.x) && (currVec.x <= botRightCorner.x))
{
if((currVec.y >= leftHandCorner.y) && (currVec.y <= botRightCorner.y))
{
totalMag += VF.field[i].length(); //add magnitude of actual vector (NOT position. did that once ...)
}
}
}
return totalMag;
}
//add motion to the given indices (i.e. x pixels of captured screen)
inline vector <int> application::addRandomMotionXBoundary(int beginIndex, int numIndices, vector <int> resolutionArr)
{
int endIndex = beginIndex + numIndices;
if( (beginIndex + numIndices) <= resolutionArr.size() )
{
for(int i = beginIndex; i < (endIndex + 1); i++)
{
resolutionArr[i] = 1;
}
}
else
{
throw "Vector's given size is not compatible with the indices given";
}
return resolutionArr;
}