A threaded font loader?

Hi, I’m trying to load ofTrueTypeFont in a different thread.
But If I try to load font on different thread, I get the following error.

I think it has to do with font using a texture, but I don’t know how to disable using the texture like in ofImage there’s setUseTexture(false);

Here’s my code below.
In ofApp.h

class fontLoaderThread : public ofThread {
    void loadFont(ofTrueTypeFont& font, const string &path, const int size)
        _font = &font;
        _path = path;
        _size = size;
    ofTrueTypeFont *_font;
    string _path;
    int _size;
    void threadedFunction()
        while (isThreadRunning()) {
            if (lock()) {
                _font->load(_path, _size);

class ofApp : public ofBaseApp{
		void setup();
		void update();
		void draw();
		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y);
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void mouseEntered(int x, int y);
		void mouseExited(int x, int y);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);

fontLoaderThread loader;
ofTrueTypeFont font;


In ofApp.cpp

void ofApp::setup(){
    loader.loadFont(font, "/path/To/font.ttf", 30); //error here

Any suggestion?

Or is it not even a usual thing to load font in a different thread?
maybe it’s not necessary because it’s fast enough to load fonts?
I would appreciate any advice!!

there’s no way at the moment to use ofTrueTypeFont on a different thread cause as you say it loads the texture when loading. we could add a setUseTexture methods like with ofImage but an ofTrueTypeFont is usesless without a texture so perhaps there’s a better way of saying ofTTF to load in 2 steps,once for the pixels and then the texture.

is it being too slow for you or why do you want to load it in a different thread?

1 Like

Thank you for your answer @arturo

is it being too slow for you or why do you want to load it in a different thread?

No, I haven’t really tested yet to find out if the loading is slow or not.
I just thought it would be wise to load fonts in a different thread to prevent potential FPS drops(or a frame stutter) when loading large font files.
But as you said it looks like it’s not possible to do a threaded font loading at the moment anyway.
I will report here later If I find the font loading too slow to use.