Hello! My project is taking a live video, looking at and storing the xth and yth pixel color in a 2d array, then generating a pixelized version with squares.
I update each frame like this:
void ofApp::update(){
capture.update(); // update with new frame
ofPixels pixel = capture.getPixels();
if (capture.isFrameNew()) {
ofColor color;
//in a 2D way, get a color in each gridsized pixel
for (int x = 0; x < ofGetWidth()-gridSize; x += gridSize) {
for (int y = 0; y < ofGetHeight()-gridSize; y += gridSize) {
//assign color
color = pixel.getColor(x, y);
//save the color in the 2D array [makes it easier for squares]
colors[x][y] = color;
}
}
}
}
to mesh well with the square drawing :
for (int x = 0; x < ofGetWidth(); x += gridSize) {
// step through vertically
for (int y = 0; y < ofGetHeight(); y += gridSize) {
//can't set them at x, x is only the width and this is 2D
ofSetColor(colors[x][y]);
ofDrawRectangle(x, y, gridSize, gridSize);
}
}
The problem is, I am occasionally getting an EXC_BAD_ACCESS error, and I don’t understand what is causing it?
As you can see, the project occasionally crashes immediately, but sometimes it is fine with running and adjusting the grid. At first I thought that it was some sort of array overflow error, but it doesn’t seem like that would not trigger at any point.