two different behaivor with the same program

Hi, im having a problem with this code, i cant understand why is it and im asking myself maybe this is a bug ?

The first time i run the program with “build and go” in xcode the OF program works in the way it should be, but then when i run the compiled program, it doesnt works in the way it should and some images are missed, anybody have and idea of what is going wrong?

thanks!

here is the code:

  
  
  
#include "testApp.h"  
#include "stdio.h"  
  
//--------------------------------------------------------------  
//testApp::testApp(){  
  
//}  
  
//--------------------------------------------------------------  
void testApp::setup(){  
	//ofSetBackgroundAuto(false);   
    int cant = 0;  
    int r,g,b,a = 0;  
    int pos = 0;  
    int gray = 0;  
	  
	int sube = 0;  
  
    if (img.loadImage("colores.png")){  
        cout << "Image loaded." << endl;  
        cout << "image original type: " << img.type << endl;  
        // Convert image to RGBA  
        if (img.type != 2){  
            img.setImageType(OF_IMAGE_COLOR_ALPHA);  
            cout << "image change type: " << img.type << endl;  
            img.update();  
        }  
        switch (img.type){  
            case 0: cant = 1; //GS  
                    break;  
            case 1: cant = 3; //RGB  
                    break;  
            case 2: cant = 4; //RGBA  
                    break;  
        }  
  
        int w = img.width;  
        int h = img.height;  
  
        unsigned char *pixRGB = img.getPixels();  
        unsigned char highlights[w * h * cant];  
        unsigned char mids[w * h * cant];  
        unsigned char shadows[w * h * cant];  
  
        for (int i = 0; i < w; i++){ // rows X  
            for (int j = 0; j < h; j++){ // columns Y  
                pos = (i * h + j) * cant;  
                r = pixRGB[pos + 0];  
                g = pixRGB[pos + 1];  
                b = pixRGB[pos + 2];  
                a = pixRGB[pos + 3];  
                //cout << "r=" << r << " g=" << g << " b=" << b << endl;  
                gray = (r + g + b) / 3;  
                // For pixels highlights  
                if (gray > 205 && gray <= 255 ){  
                    highlights[pos + 0] = r;  
                    highlights[pos + 1] = g;  
                    highlights[pos + 2] = b;  
                    highlights[pos + 3] = a;  
                }  
                else {  
                    highlights[pos + 0] = 0x000000; // r  
                    highlights[pos + 1] = 0x000000; // g  
                    highlights[pos + 2] = 0x000000; // b  
                    highlights[pos + 3] = 0x000000; // a  
                }  
                // For pixels mids  
                if (gray > 100 && gray < 205){  
                    mids[pos + 0] = r;  
                    mids[pos + 1] = g;  
                    mids[pos + 2] = b;  
                    mids[pos + 3] = a;  
                }  
                else{  
                    mids[pos + 0] = 0x000000; // r  
                    mids[pos + 1] = 0x000000; // g  
                    mids[pos + 2] = 0x000000; // b  
                    mids[pos + 3] = 0x000000; // a  
                }  
                // For pixels shadows  
                if (gray > 0 && gray < 100){  
                    shadows[pos + 0] = r;  
                    shadows[pos + 1] = g;  
                    shadows[pos + 2] = b;  
                    shadows[pos + 3] = a;  
                }  
                else{  
                    shadows[pos + 0] = 0x000000; // r  
                    shadows[pos + 1] = 0x000000; // g  
                    shadows[pos + 2] = 0x000000; // b  
                    shadows[pos + 3] = 0x000000; // a  
                }  
            }  
        }  
        imgH.setFromPixels(highlights, w, h, OF_IMAGE_COLOR_ALPHA);  
        imgM.setFromPixels(mids, w, h, OF_IMAGE_COLOR_ALPHA);  
        imgS.setFromPixels(shadows, w, h, OF_IMAGE_COLOR_ALPHA);  
    }  
    else  
        cout << "Error: Image not load" << endl;  
  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
  
}  
  
  
//--------------------------------------------------------------  
void testApp::draw(){  
	sube = sube + 1;  
    //ofSetupScreen();  
    img.draw(0, 0);  
  
    ofSetColor(0xFFFFFF);  
    ofEnableAlphaBlending();  
    imgH.draw(img.width, sube);  
    imgM.draw(sube, img.height);  
    imgS.draw(img.width, img.height + sube);  
    ofDisableAlphaBlending();  
}  
  
//--------------------------------------------------------------  
void testApp::keyPressed  (int key){  
  
}  
  
//--------------------------------------------------------------  
void testApp::keyReleased(int key){  
  
}  
  
//--------------------------------------------------------------  
void testApp::mouseMoved(int x, int y ){  
}  
  
//--------------------------------------------------------------  
void testApp::mouseDragged(int x, int y, int button){  
}  
  
//--------------------------------------------------------------  
void testApp::mousePressed(int x, int y, int button){  
  
}  
//--------------------------------------------------------------  
void testApp::mouseReleased(int x, int y, int button){  
  
}  

Check if the images are correctly loaded.
To open a console outside of xcode, right clic on your application, then “Show package contents”, “Contents” folder, “MacOS”, then on the binary :slight_smile:

And be sure that you the “data” folder is in the same folder than the application when you launch it.

hi, ive tried what you say, if i go to show packages content, then contents, then macosx and then i execute the binary, the programs works fine, it works as it should be, but if i run the in the traditional way the compiled app it doenst load the pictures, ive also checked that my pics are inside the data folder , any idea of what is going on?