I have a data.h file and a data.cpp in my project where I keep all my classes. I want to add a .draw() method to a class so that it draws text when called in testApp.cpp. This is the method
void textObjectCollection::draw () {
for (int i=data.size(); i==0; i--) {
float aNumber = float(i)/float(data.size());
float scale = if (aNumber > 0.5) {aNumber} else {0.5} ;
ofPushMatrix();
ofSetColor(255,255,200);
ofScale(scale,scale,1);
---->> this is the problematic line -----> someFont.drawString(data[i].text, data[i].x, data[i].y);
ofPopMatrix();
}
in the constructor I have
textObjectCollection::textObjectCollection () {
someFont.loadFont("Microsoft Sans Serif.ttf", 24, true, true);
}
If I comment out the problematic line my app works fine - else it gets compiled and then I get an : EXC_BAD_ACCESS error and stops
how can I do this ?? It is way more convient to have a .draw() in my class than pass data from it to a draw method in testApp.cpp
try loading the font outside of the constructor, in a setup method for example. depending where you are instantiating the class, since it has to reserve opengl resources, doing it in the constructor can be problematic
class textObject {
public:
string text; // to hold the text
int x; // to hold x coordinate
int y; // to hold y coordinate
string date; // to hold the date
unsigned fontSize;
textObject (string, int, int, string, unsigned);
//~textObject ();
void move (int posx, int posy);
void appendToFile (string filename);
int textSize ();
};
class textObjectCollection {
ofTrueTypeFont someFont;
public:
deque <textObject> data;
textObjectCollection ();
void add (textObject object);
unsigned size ();// add an element to tail
void draw ();
void setup ();
// void remove (); // remove an element from start
// void autoRemove (int n); // remove an element from start when size exceeds n
};