ofPixels throwing exception well inside xy bounds

As there has been a fix using size_t in ofPixels just recently, I am facing issues with code that worked well on 0.9.4 windows10:

Exception thrown at 0x00000001403EBD4C in example3J-test1_debug.exe: 0xC0000005: Access violation reading location 0x000000000FD5F0D3.

it is in getColor(x,y) where x and y are well inside their bounds and the image was loaded before.

is this a known behaviour?

the debugger breaks at

template<typename PixelType>
ofColor_<PixelType> ofPixels_<PixelType>::Pixel::getColor() const{
    ofColor_<PixelType> c;
    switch(pixelFormat){
        case OF_PIXELS_RGB:
            c.set( pixel[0], pixel[1], pixel[2] );
            break;
        case OF_PIXELS_BGR:
            c.set( pixel[2], pixel[1], pixel[0] );
            break;
        case OF_PIXELS_RGBA:
            c.set( pixel[0], pixel[1], pixel[2], pixel[3] ); // <<-----

i wrote a small program and can replicate this behaviour. let me know and i will send you the src-code.

ah, i am talking about of 0.9.6 windows 64:
http://openframeworks.cc/versions/v0.9.6/of_v0.9.6_vs_release.zip

1 Like

We are discussing this over here – can you paste your example:

https://github.com/openframeworks/openFrameworks/issues/5321

straight forward. the image is a simple png with transparency:

#include "ofApp.h"
#include "assert.h"

ofImage image;

//--------------------------------------------------------------
void ofApp::setup(){
    bool b = image.load("test.png");
    assert(b);

    float x, y;
    ofColor color;
    for (size_t i = 0; i < 200000; i++)
    {
        do
        {
            x = floor(ofRandom(image.getWidth()));
            y = floor(ofRandom(image.getHeight()));

            // not necessary, just to make sure
            x = ofClamp(x, 0, image.getWidth() - 1);
            y = ofClamp(x, 0, image.getHeight() - 1);
            //ofLogNotice("setup") << "xy: " << x << " " << y;

            color = image.getColor(x, y);
        } while (color.a < 20);

        if (!(i % 100)) cout << ".";
    }
    cout << endl;
}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){
    ofPushMatrix();
    ofScale(0.1, 0.1);
    image.draw(0,0);
    ofPopMatrix();
}

//--------------------------------------------------------------