ofTrueTypeFont::drawString - Error

anyone know how to fix this?

  
[error] ofTrueTypeFont::drawString - Error : font not allocated -- line 756 in /Users/lukaszwieczorek/Documents/of_v0073_osx_release/libs/openFrameworksCompiled/project/osx/../../../openFrameworks/graphics/ofTrueTypeFont.cpp  

Kyle says to get newest version (I have 0073, the newest unless there is a non-released one) and I have done what he suggest about moving loadFont, but that doesn’t seem to help

pulling from this post http://forum.openframeworks.cc/t/truetype-font-loading-problem-on-.h-file-[solved]/7859/0

here is the code:

  
#include "testApp.h"  
  
void testApp::setup(){  
      
	bLearnBackground = false;  
      
    vidGrabber.setVerbose(true);  
    vidGrabber.initGrabber(320,240);  
      
    colorImg.allocate(320,240);  
    grayImage.allocate(320,240);  
    grayBg.allocate(320,240);  
    grayDiff.allocate(320,240);  
      
    // UI  
      
    float dim = 20;  
	float xInit = OFX_UI_GLOBAL_WIDGET_SPACING;  
    float length = 320-xInit;  
	  
    drawPadding = false;  
      
    gui = new ofxUICanvas(660, 60, length+xInit, ofGetHeight());  
    gui->addSlider("sliderThreshold", 0.0, 255.0, sliderThreshold, length-xInit,dim);  
      
    ofAddListener(gui->newGUIEvent,this,&testApp::guiEvent);  
      
    // TEXT  
    myFont.loadFont("KLAVIKAR.TTF", 32);  
}  
  
void testApp::update(){  
    vidGrabber.update();  
    //do we have a new frame?  
    if (vidGrabber.isFrameNew()){  
		colorImg.setFromPixels(vidGrabber.getPixelsRef());  
        grayImage = colorImg; // convert our color image to a grayscale image  
        if (bLearnBackground == true) {  
            grayBg = grayImage; // update the background image  
            bLearnBackground = false;  
        }  
		grayDiff.absDiff(grayBg, grayImage);  
        grayDiff.threshold(sliderThreshold);  
		contourFinder.findContours(grayDiff, 5, (340*240)/4, 4, false, true);  
    }  
}  
  
  
  
  
  
void testApp::draw(){  
    //UI stuff  
	  
	ofPushStyle();  
	ofEnableBlendMode(OF_BLENDMODE_ALPHA);  
	ofPopStyle();  
      
    // openCV  
      
    //centroid = contourFinder.blobs.at(0).centroid;  
      
	ofSetHexColor(0xffffff);  
    colorImg.draw(0, 0, 320, 240);  
	grayDiff.draw(0, 240, 320, 240);  
    ofRect(320, 0, 320, 240);  
    contourFinder.draw(320, 0, 320, 240);  
	ofColor c(255, 255, 255);  
	for(int i = 0; i < contourFinder.nBlobs; i++) {  
		ofRectangle r = contourFinder.blobs.at(i).boundingRect;  
		r.x += 320; r.y += 240;  
		c.setHsb(i * 64, 255, 255);  
		ofSetColor(c);  
		ofRect(r);  
	}  
      
    //render text  
    ofSetHexColor(0xe0e0e0);   
      
    stringstream ss;  
    ss << "Blob: ";  
    // make sure there is at least one blob, so that we can get the first one //  
    if(contourFinder.blobs.size() > 0) {  
        // pull out the centroid, which is an ofPoint / ofVec3f  
        ofVec3f centroid = contourFinder.blobs[0].centroid;  
        // store the x,y,z coords from the centroid in the string  
        ss << centroid << endl;  
        ofFill();  
        ofCircle( centroid, 20 );  
    } else {  
        ss << " NOT FOUND." << endl;  
    }  
    ofDrawBitmapString( ss.str().c_str(), 20, 20);  
      
      
    for(int i = 0; i < contourFinder.blobs.size(); i++ ) {  
        ofVec3f centroid = contourFinder.blobs[i].centroid;  
          
    }  
      
    myFont.drawString("Visualheroizer", 660, 70);  
    //cout << "Hello, World!\n";  
  
  
      
}  
void testApp::keyPressed(int key) {  
	bLearnBackground = true;  
      
    // UI Stuff  
    switch (key)  
    {  
        case 'p':  
        {  
            drawPadding = !drawPadding;  
            gui->setDrawWidgetPadding(drawPadding);  
        }  
            break;  
              
        case 'g':  
        {  
            gui->toggleVisible();  
        }  
            break;  
        default:  
            break;  
    }  
}  
void testApp::guiEvent(ofxUIEventArgs &e)  
{  
	string name = e.widget->getName();  
	int kind = e.widget->getKind();  
	  
	if(name == "sliderThreshold")  
	{  
		ofxUISlider *slider = (ofxUISlider *) e.widget;  
		sliderThreshold = slider->getScaledValue();  
        cout << "value: " << slider->getScaledValue() << endl;  
	}  
	    else if(name == "RSLIDER")  
    {  
        ofxUIRangeSlider *rslider = (ofxUIRangeSlider *) e.widget;  
        cout << "valuelow: " << rslider->getScaledValueLow() << endl;  
        cout << "valuehigh: " << rslider->getScaledValueHigh() << endl;  
    }  
    else if(name == "PAD")  
    {  
        ofxUI2DPad *pad = (ofxUI2DPad *) e.widget;  
        cout << "value x: " << pad->getScaledValue().x << endl;  
        cout << "value y: " << pad->getScaledValue().y << endl;  
    }  
    else if(name == "CSLIDER" || name == "CSLIDER 2")  
    {  
        ofxUIRotarySlider *rotslider = (ofxUIRotarySlider *) e.widget;  
        cout << "value: " << rotslider->getScaledValue() << endl;  
    }  
}  
  
void testApp::exit()  
{  
    delete gui;  
}  
  
//void ofxCvImage::blurGaussian(int value=3);  
  
//--------------------------------------------------------------  
void testApp::keyReleased(int key){  
      
}  
  
//--------------------------------------------------------------  
void testApp::mouseMoved(int x, int y )  
{  
	  
}  
  
//--------------------------------------------------------------  
void testApp::mouseDragged(int x, int y, int button)  
{  
      
}  
  
//--------------------------------------------------------------  
void testApp::mousePressed(int x, int y, int button)  
{  
      
}  
  
//--------------------------------------------------------------  
void testApp::mouseReleased(int x, int y, int button)  
{  
      
}  
  
//--------------------------------------------------------------  
void testApp::windowResized(int w, int h)  
{  
      
      
}  
  
//--------------------------------------------------------------  
void testApp::gotMessage(ofMessage msg){  
      
}  
  
//--------------------------------------------------------------  
void testApp::dragEvent(ofDragInfo dragInfo){  
      
}  

couldn’t help but notice that you typed KLAVIKAR.TTF … instead of KLAVIKA.TTF

or… even better: klavika.ttf

nope. its definitely “KLAVIKAR.TTF” (in uppercase too). It loads fine, just get that error for some reason :confused:

I have of 007 and I’ve compared the ofTrueTypeFont from the repo

and it appears identical, you can grab that and replace it in your OF if you see any differences on your code…

I think the problem is that you are not calling the constructor in thus not initializing the bLoadedOk bool.

So what happens… is that in some machines…it is initialized as true, and in other machines as false…

try making your myfont a pointer like that:

  
  
myFont = new ofTrueTypeFont();  
myFont->loadFont("klavika.ttf", 20);  
  

(and in your testApp.h)

  
ofTrueTypeFont *myFont;  
  

klavika.ttf.zip

The constructor will be called by default when the object is created (which in this case is when the app starts up). Are you sure there’s no errors in the loadFont() method? If you could walk through that method in the debugger you should be able to see if there’s any errors. If you’re sure it’s in the right place perhaps you could switch out the fonts just to see if it might somehow be the TTF file itself? Your code looks right, so it’s either the font file or the location of the font file that’s causing the problem

Use this after setting UICannvas

  
  
gui->setFont("Fett.ttf",32);  
  

fett.ttf is my required font you can change it