Declaring ofMesh in ofApp.h causes EXC_BAD_ACCESS

Hi all,

I have a project where I have two ofMesh objects. It works if I declare the ofMesh objects outside of the methods in ofApp.cpp, but if I declare them as properties in ofApp.h I get EXC_BAD_ACCESS when I try to mesh2.addVertex(ofPoint(0,0,0)); in setup().

OF 0.8.4
Xcode 6.1.1
Mac OS 10.10.2

Is this something anyone else has run into? I’m just curious why, and if I’m doing something wrong.
If not, I’ll provide sample code…

Thanks!

C

I have definitely been experiencing this problem dealing with meshes. Creating a new project and swapping out the code gets rid of the problem, but did you just recently update xcode? This started happening immediately after I updated.

That is odd. Can you post your sample code? Ideally with the least amount of code it takes to trigger the crash.

try cleaning the project and rebuilding, xcode sometimes crashes in random places and it’s usually fixed by cleaning and rebuilding

I created a new project and copied the src code in, and it’s fixed. Thanks AceSlowman!

I also did as you suggested arturo, and cleaned the project. Lo and behold, now they both run with no crash.

Slightly embarrassed I didn’t try cleaning the project first…

Thanks again for the help!

For the record though, here’s the code:

ofApp.h:

//ofApp.h
#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void draw();

		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y );
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);
    

    int drawMode;
    
    ofMesh mesh;
    ofMesh mesh2;

    
		
};

ofApp.cpp:

void ofApp::setup(){
  
    drawMode = 0;
    
    // first mesh
    mesh.addVertex(ofPoint(0,0,0));
    mesh.addColor(ofFloatColor(0,0,0));  // add a color at that vertex
    
    mesh.addVertex(ofPoint(10,0,0));
    mesh.addColor(ofFloatColor(0,0,0));  // add a color at that vertex
    
    mesh.addVertex(ofPoint(0,0,10));
    mesh.addColor(ofFloatColor(0,0,0));  // add a color at that vertex
    
    mesh.addIndex(0);
    mesh.addIndex(1);
    mesh.addIndex(2);

    // second mesh
    mesh2.addVertex(ofPoint(0,0,0));
    mesh2.addColor(ofFloatColor(0,0,0));  // add a color at that vertex

    mesh2.addVertex(ofPoint(10,0,0));
    mesh2.addColor(ofFloatColor(0,0,0));  // add a color at that vertex

    mesh2.addVertex(ofPoint(0,0,10));
    mesh2.addColor(ofFloatColor(0,0,0));  // add a color at that vertex

    
    mesh2.addIndex(0);
    mesh2.addIndex(1);
    mesh2.addIndex(2);
 
    
    
}

And here’s a screencap of the crash (still waiting for it to be processed):

*edit * grammar