Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

iOS Adding Custom Files Issue on XCode

$
0
0

@hypnoticfart wrote:

I’m having an issue where any time I try to call an oF function (e.g. ofGetWidth()) from a file outside of “ofApp.*” , I get a runtime error. The program will build correctly, but will not run on the simulator. I have the same code running correctly on OSX with openframeworks and can’t seem to pin it down.

Here’s what I think I’m doing wrong: Adding my own files/classes to XCode.

Here are the steps I’ve taken:

1.) Created an empty oF project with the project generator. It built correctly and ran on the simulator correctly.
2.) If I call ofGetWidth()/ofGetHeight() or any other oF method, it works fine. I just print the size of the screen to the middle of the application and run it in the simulator. Works fine.
3.) I create a class called TouchDrawCircle and addd it to XCode. I have tried adding it into “src” and “local_addons”. The code is below, but I am just trying to run a simple draw method.
4.) When I include “TouchDrawCircle.h” in “ofApp.h”, the program builds correctly and then crashes on runtime with the simulator. It always crashes when I’m calling ofGetWidth() from my added TouchDrawCircle.cpp class.

I’m sure I’m making a very silly error, but I can’t figure it out. Any help would be greatly appreciated. Here is the code:

//

//  TouchDrawCircle.hpp

//  touchTest

//

//  Created by Jonathan Honning on 2/13/19.

//



#ifndef TouchDrawCircle_hpp

#define TouchDrawCircle_hpp



#include <stdio.h>

#include "ofMain.h"



class TouchDrawCircle{

    

public:

    TouchDrawCircle();

    void setCoords(int newX, int newY){x = newX; y = newY;}

    void draw();

    

private:

    int radius;

    int x = 0;

    int y = 0;

    

};



#endif /* TouchDrawCircle_hpp */

//

//  TouchDrawCircle.cpp

//  touchTest

//

//  Created by Jonathan Honning on 2/13/19.

//



#include "TouchDrawCircle.hpp"



TouchDrawCircle::TouchDrawCircle()

{

    radius = 5;

    x = ofGetWidth() * 0.5;

    y = ofGetHeight() * 0.5;

}



void TouchDrawCircle::draw()

{

    ofDrawCircle(x,y,radius);

}
//ofApp.h



#pragma once



#include "ofxiOS.h"

#include "TouchDrawCircle.hpp"



class ofApp : public ofxiOSApp{

    

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);

    

    std::string displayString = "Init";

    bool didLoseFocus = false;

    bool didDoubleTouch = false;

    

    TouchDrawCircle circle;

};
//ofApp.mm
#include "ofApp.h"



//--------------------------------------------------------------

void ofApp::setup(){

    

}



//--------------------------------------------------------------

void ofApp::update(){

    

}



//--------------------------------------------------------------

void ofApp::draw(){

    ofSetColor(0, 0, 0);

    ofDrawBitmapString(displayString, ofGetWidth() * 0.5, ofGetHeight() * 0.5);

    

    circle.draw();

}



//--------------------------------------------------------------

void ofApp::exit(){

    

}



//--------------------------------------------------------------

void ofApp::touchDown(ofTouchEventArgs & touch){

    circle.setCoords(touch.x,touch.y);

    

    if(didDoubleTouch == false)

    {

        displayString = "Touch Down!";

    }

}



//--------------------------------------------------------------

void ofApp::touchMoved(ofTouchEventArgs & touch){

    circle.setCoords(touch.x,touch.y);

    

    displayString = "We're Moving!";

    didDoubleTouch = false;

}



//--------------------------------------------------------------

void ofApp::touchUp(ofTouchEventArgs & touch){

    if(!didDoubleTouch)

    {

        displayString = "Done touching!";

        didDoubleTouch = false;

    }

    

}



//--------------------------------------------------------------

void ofApp::touchDoubleTap(ofTouchEventArgs & touch){

    didDoubleTouch = true;

    displayString = "Touchy touchy!";

}



//--------------------------------------------------------------

void ofApp::touchCancelled(ofTouchEventArgs & touch){

    

}



//--------------------------------------------------------------

void ofApp::lostFocus(){

    didLoseFocus = true;

}



//--------------------------------------------------------------

void ofApp::gotFocus(){

    if(didLoseFocus)

    {

        displayString = "Lost focus but got it back!";

    }

}



//--------------------------------------------------------------

void ofApp::gotMemoryWarning(){

    

}



//--------------------------------------------------------------

void ofApp::deviceOrientationChanged(int newOrientation){

    

}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles