using ofGetHeight in external file, Xcode

Hi all,

I’m trying to compile a basic example of an of app for ipad with the ios emulator on OSX 10.8 in xcode 4.6.2.
Everything works fine at first, and calling ofGetHeight in testApp::setup() works and prints to the console nicely.
Then I created an external file to put a basic boucing ball class (entire class in a .h like TouchAndAccelExample).
The problem comes when I call ofGetHeight() in the class. When the app compiles and launches, xcode goes into debugging mode and stops the app at this call ofGetHeight.
the error looks like this:

Thread 1: EXC_BAD_ACCESS (code=2, address=0x8)

at line:

ofPoint ofAppiPhoneWindow::getWindowSize() {
return *[[ofxiOSEAGLView getInstance] getWindowSize]; //<< HERE
}

in file:
ofAppiPhoneWindow.mm

Any advice? I compared all my build setting to the TouchAndAccelExample and everything looks the same.
If you need I can upload the project, don’t where to though.

Hey I think some code would help. You can always paste it inline using the code tag or attach it as a zip, or put it on here http://pastebin.com/

All right here we go:

ball.h

  
#pragma once  
  
#include "ofMain.h"  
#include "ofxiPhone.h"  
#include "ofxiPhoneExtras.h"  
#include "ofxOsc.h"  
#include <iostream>  
  
class Ball {  
    public:  
        float x, y, xspeed, yspeed;  
      
        Ball(){  
            x = ofGetWindowWidth()/2.;  
            y = ofGetWindowHeight()/2.;  
            xspeed = ofRandom(2, 10);  
            yspeed = ofRandom(2, 10);  
        }  
      
        void update(){  
            if(x>ofGetWindowWidth() || x< 0){  
                xspeed *= -1;  
            }  
            if(y>ofGetWindowHeight() || y< 0){  
                yspeed *= -1;  
            }  
            x += xspeed;  
            y += yspeed;  
        }  
      
        void display(){  
            ofCircle(x,y, 30);  
        }  
};  

testApp.mm (left out all the ios functions in this paste, they are all empty in my code)

  
#include "testApp.h"  
  
//--------------------------------------------------------------  
void testApp::setup(){  
    ofSetLogLevel(OF_LOG_VERBOSE);  
	  
	// initialize the accelerometer  
	ofxAccelerometer.setup();  
    cout<<"height"<< ofGetHeight()<<endl;  
	  
	//If you want a landscape oreintation   
    //iPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT);  
  
	ofBackground(0,0,0);  
      
  
  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
    daball.update();  
      
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
    daball.display();  
  
	  
}  
  
//--------------------------------------------------------------  
void testApp::exit(){  
  
}  
  

and testApp.h

  
#pragma once  
  
#include "ofMain.h"  
#include "ofxiPhone.h"  
#include "ofxiPhoneExtras.h"  
#include "ofxOsc.h"  
#include "ball.h"  
  
class testApp : public ofxiPhoneApp{  
	  
    public:  
        void setup();  
        void update();  
        void draw();  
        void exit();  
	  
        void touchDown(ofTouchEventArgs & touch);  
        void touchMoved(ofTouchEventArgs & touch);  
        void touchUp(ofTouchEventArgs & touch);  
        void touchDoubleTap(ofTouchEventArgs & touch);  
        void touchCancelled(ofTouchEventArgs & touch);  
  
        void lostFocus();  
        void gotFocus();  
        void gotMemoryWarning();  
        void deviceOrientationChanged(int newOrientation);  
      
        Ball daball;  
      
  
};  

I should also mention that I used the ios project generator and I’m using OF ios 0.7.4

it could be the constructor is getting called before the EAGLView is setup, it could be getting inlined by the compiler or something more or less equivalent. Notice that in the touchaccel example it only uses of* in an init() function

Maybe try remove the constructor and put its code in a setup() function in ball.h, then in testApp::setup() call daball.setup()

Yes that was it! I made a setup function and it works! Thank You!!