EXC_BAD_ACCESS on assigning a value to a string variable

I’m really struggling with assigning new values to hour / minute and second. Curriously the utils/xmlExample does work, where a message variable is changed all over the place. Can somebody tell my why this is happening?


#pragma once

#include "ofMain.h"

class ofApp : public ofBaseApp{

	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 h;
    int m;
    int s;
    int height;
    int width;
    string hour;
    string minute;
    string second;



#include "ofApp.h"
#include <iostream>

void ofApp::setup(){
    h = ofGetHours();
    m = ofGetMinutes();
    s = ofGetSeconds();
    width = ofGetWindowWidth();
    height = ofGetWindowHeight();
    second = "7"; //<----- EXC_BAD_ACCESS

might be already taken - does try changing second to mySecond just to see

Still the same. Even with something like mysuperspecialsecond. There’s really not much more added to this newly generated project. Only some usage in in update() & draw() of those defined variables.

what OS are you on? I just tried your code on OF 8.4/Mac OS X 10.10 and it worked ok

I’ve downloaded the latest openFrameworks and I’m on OSX 10.10.1 and I can’t see any issue, too. Even the example project I mentioned in the first post does work flawlessly. I’ll later try to generate a second project and see if just copy pasting works :smile:

Yeah, opening a new project and copy pasting really solved the issue. I’ve no clue what I did wrong in the first project. I didn’t really change other stuff, than the posted one.

ha - I just ran into this today - cleaning the project and restarting xcode worked here :rage:

I’ve had the same with a std::map, member of ofApp. @jvcleave’s solution worked for me. What a perky problem.