Error with ofPixels

Hi!
I got this error and it opens the ofPixels.h file at line 795
c.set( pixel[0], pixel[1], pixel[2] );

Actually without changing anything in the code the error occurs like 2 in 3 times, not every time.

I am on PC with visual studio. I am working with this tutorial : http://openframeworks.cc/ofBook/chapters/generativemesh.html and I started customize it by adding these lines in the void ofApp::draw()

    int numVerts = mesh.getNumVertices();

    for (int i = 0; i < numVerts; ++i) {

        ofVec3f vert = mesh.getVertex(i);

        int x = int(vert.x);
        int y = int(vert.y);

        ofColor couleur = image.getColor(x, y);
        ofSetColor(couleur);
        ofFill();

        ofDrawEllipse(vert.x, vert.y, 10, 10);

    }

The problem seems to be with the getColor function maybe

I am a beginner with openframeworks and visual studio

If you have any question or if I am not clear, ask me

Thanks

I was getting that same error a few days ago, although on Xcode. Cleaning and rebuilding the project fixed it.

Thanks! But it didn’t work. I cleaned and rebuilt both the solution and the project but it’s still not working. Now it never works.
I don’t have the Microsoft Visual Studio warning window anymore, but it is stuck at the same line.
I am with of 0.9.2

Edit : I cleaned the openframeworks lib and it worked well once but now it’s still doing the same error

This is odd.
I cant see any problem in the code.

@arturo do you have any idea about what might be going on?

Best

that’s usually because you are trying to access a position in the pixels that doesn’t exist. try printing out the values or at least storing them in a variable so you can see them in the debugger:

auto pixelIndex = image.getPixels().getPixelIndex(x,y);
auto maxIndex = image.getPixels().size();

if pixelIndex is >= than maxIndex then you are outside of the pixels memory. you can also use an if condition to not try to get the color in that case

Both the pixelIndex and the maxIndex are 48600, which is quite strange because my image is originally 1600654px, I resized it to 200x81px (so 16 200px). 48600 is 162003 but I don’t see if there’s a link.

I think the problem happens the first time as you say, when I tried to access position of pixels that doesn’t exist, with this code (because I had a strange color pattern) :
for (int i = 0; i < numVerts*2; ++i) {

}
But even after I have changed it and cleaned the project it seems to be like it is still “in cache”.

Edit : I scaled ofColor couleur = image.getColor(x, y); to ofColor couleur = image.getColor(x/8, y/8); (8 is the factor I used for resizing) and it works, the problem should initially come from that.

Thanks!