Texture wrapping w/ image onto .obj model in Xcode

Hey OF community!

Hope you’re doing well :slight_smile:

I am running into what I am deducting as a memory issue with my program, but i’ll need a second (or 3rd, 4th,etc) to clarify. I am using the ofxObjLoader fine with my imported model (limiting the amount of faces rendered in final file). I had followed the openFrameworks tutorials on generating a texture from an image, and applying it to an ofMesh object. Everything compiles, but I am left with this issue below in my Xcode IDE:

example-objLoadDebug(30467,0xa085f1a8) malloc: *** mach_vm_map(size=1073741824) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
libc++abi.dylib: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc

I am using a Mac Mini mid 2011. Here is my cpp file:

    #include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){
    ofBackground(0);
    ofSetFrameRate(30);

	ofxObjLoader::load("danny2.obj", original, true);
    ofxObjLoader::save("sphere_saved.obj", original);
    ofxObjLoader::load("sphere_saved.obj", saved, false);
    texture.loadImage("texture.jpg");
    
    
    cout << " num vertices " << original.getNumVertices() << " " <<  saved.getNumVertices() <<  endl;
    cout << " num texcords " << original.getNumTexCoords() << " " <<  saved.getNumTexCoords() << endl;
    cout << " num normals " << original.getNumNormals() << " " <<  saved.getNumNormals() << endl;
    cout << " num indices " << original.getNumIndices() << " " <<  saved.getNumIndices() << endl;

    radians = 3.14;
    
    
    original.setMode(OF_PRIMITIVE_POINTS);
    
    float intensityThreshold = 150.0;
    int w = texture.getWidth();
    int h = texture.getHeight();
    for (int x=0; x<w; ++x) {
        for (int y=0; y<h; ++y) {
            ofColor c = texture.getColor(x, y);
            float intensity = c.getLightness();
           // if (intensity >= intensityThreshold) {
                ofVec3f pos(2*x, 2*y, 0.0);
                original.addVertex(pos);
                original.addColor(c);
            //}
        }
    }
    
  
    
    
  }

//--------------------------------------------------------------
void testApp::update(){
    
    ry += 0.90;
    


}


//--------------------------------------------------------------
void testApp::draw(){
    
    cam.setPosition(original.getCentroid() + ofVec3f(0,0,mouseY/10));
    cam.lookAt(original.getCentroid(), ofVec3f(0,1,0));
    
    
    ofColor centerColor = ofColor(85, 78, 68);
    ofColor edgeColor(0, 0, 0);
    ofBackgroundGradient(centerColor, edgeColor, OF_GRADIENT_CIRCULAR);
    
    
	cam.setPosition(original.getCentroid() + ofVec3f(0,0,mouseY/10)); //pulls forward and back from centroid of .OBJ file.
    cam.lookAt(original.getCentroid(), ofVec3f(0,1,0));
  
    
    
    cam.begin();
    //ofSetColor(255);

    ofTranslate(100,100);
    
    ofRotateY(ry);

    ofRotateX(ofRadToDeg(radians/1.8));

    
    
    
	if(ofGetMouseX() > ofGetWidth()/2){
		original.drawWireframe();
	}
	else{
		saved.drawWireframe();
	}
    
    cam.end();
    

    
    
    
    original.setMode(OF_PRIMITIVE_LINES);
    
    float connectionDistance = 30;
    int numVerts = original.getNumVertices();
    
    for (int a=0; a<numVerts; ++a) {
        ofVec3f verta = original.getVertex(a);
        for (int b=a+1; b<numVerts; ++b) {
            ofVec3f vertb = original.getVertex(b);
            float distance = verta.distance(vertb);
            if (distance <= connectionDistance) {
                original.addIndex(a);
                original.addIndex(b);
            }
        }
        
    }
    
    /*

    easyCam.begin();
    ofPushMatrix();
    ofRotateY(ry);
    
    ofRotateX(ofRadToDeg(radians/1.8));

    original.drawWireframe();
    ofPopMatrix();
    easyCam.end();

*/
    
    
}

//--------------------------------------------------------------
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){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){ 

}