Hi, I am trying to use vector<ofColor>, but I got EXC_BAD_ACCESS. Xcode says Build Succeeded.
How do I use vector<ofColor> with setHsb properly?
Why does this error occur?
The vector <ofColor> colors; has no elements added to it because your for loop is using the size of the colors vector ( which is 0 ) as the number of times to loop.
That is why you are getting a memory error when trying to access colors[0].
if you wanted say 10 elements.
I would either do this:
void ofApp::setup(){
ofColor color;
int numColors = 10;
for(int i = 0; i < numColors; i++){
color.setHsb(i * 50, 222, 255);
colors.push_back(color);
}
}
or you could assign the vector to be 10 elements and then just treat like an array.