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:

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

All right here we go:


#pragma once  
#include "ofMain.h"  
#include "ofxiPhone.h"  
#include "ofxiPhoneExtras.h"  
#include "ofxOsc.h"  
#include <iostream>  
class Ball {  
        float x, y, xspeed, yspeed;  
            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);  
}; (left out all the ios functions in this paste, they are all empty in my code)

#include "testApp.h"  
void testApp::setup(){  
	// initialize the accelerometer  
    cout<<"height"<< ofGetHeight()<<endl;  
	//If you want a landscape oreintation   
void testApp::update(){  
void testApp::draw(){  
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{  
        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!!