Error without line number [solved]

I am getting a multitude of the following messages:

[ error ] ofTrueTypeFont: drawString(): font not allocated

I checked and all fonts are initialized. I’ve seen others dealing with this but their errors had line numbers. Is there a way to get the line number of this call. The project I am editing has way to many drawString calls to comment them out one by one and it also uses many sublibs that could be the source.

I tried adding the following printf into ofTrueType but the results add more mystery:

void ofTrueTypeFont::drawString(const std::string &  c, float x, float y) const{
	ofLogError() << "s:" << c << " xy " << x << " "<<y;
	if (!bLoadedOk){
		ofLogError("ofTrueTypeFont") << "drawString(): font not allocated";
		return;

results:

[ error ] s: xy 0 0
[ error ] ofTrueTypeFont: drawString(): font not allocated

what platform are you on?

Can you produce the smallest possible example that shows the error (and share the code) ?

Thanks,
zach

I’m on linux, archlinux. I cant produce an example yet, that is part of the issue. The project is a port from mac over to linux and is too large to widdle down to find the problem (hence the desire for that error’s line number). I’ll try and confirm that a small example that calls drawString() works without error so to confirm it is not a system problem

examples/fontExample compiles and runs without errors

my suggestion would be to put some print outs through the font loading process to see if it’s really loaded. if it’s actually loaded (but says it’s unloaded as you go to use it), I’d look around for memory errors – for example, an array index error or something related to memory. Sometimes I’ve had weird behavior if there’s something my code that stomps on memory. best way to debug might be to comment things out. I usually start with the draw and then update and work my way through setup.

(You could also put a breakpoint at the moment of the print out, that would give you a chance to see which font draw call is printing the error…)

thank you, ill try that. to add mystery, I commented out all of update() and draw() and yet still error showing up.

very odd, curious to see what you learn!

any ideas for getting cleaner stack traces. I added boosts stack trace to ofTrueType compiled the app with make Debug and ran the debug version but symbols still not showin:

#include <boost/stacktrace.hpp>
void ofTrueTypeFont::drawString(const std::string &  c, float x, float y) const{
	ofLogError() << boost::stacktrace::stacktrace();
	if (!bLoadedOk){
		ofLogError("ofTrueTypeFont") << "drawString(): font not allocated";
		return;
	}
	ofGetCurrentRenderer()->drawString(*this,c,x,y);
}

result:

[ error ] 0# 0x000056550A90457F in ./bin/project_debug    
1# 0x000056550A54CE2B in ./bin/project_debug
2# 0x000056550A7AD7C8 in ./bin/project_debug
3# 0x000056550A7AF99A in ./bin/project_debug
4# 0x000056550A7B60C8 in ./bin/project_debug
5# 0x000056550A7B5C1F in ./bin/project_debug
6# 0x000056550A7B55A3 in ./bin/project_debug
7# 0x000056550A819DE3 in ./bin/project_debug
8# 0x000056550A817FE2 in ./bin/project_debug
9# 0x000056550A879BFB in ./bin/project_debug
10# 0x000056550A878DFB in ./bin/project_debug
11# 0x000056550A87662E in ./bin/project_debug
12# 0x000056550A99A127 in ./bin/project_debug
13# 0x000056550A813532 in ./bin/project_debug
14# 0x000056550A81336D in ./bin/project_debug
15# 0x000056550A80CB34 in ./bin/project_debug
16# 0x000056550A80C9E0 in ./bin/project_debug
17# main in ./bin/project_debug
18# 0x00007F24AAF02310 in /usr/lib/libc.so.6
19# __libc_start_main in /usr/lib/libc.so.6
20# 0x000056550A549B65 in ./bin/project_debug
[ error ] ofTrueTypeFont: drawString(): font not allocated

sorry I usually use Xcode – are you sure you are compiling in debug? you might want to double check that and/or check with the build step looks likes, to make sure there’s no stripping happening.

Found the error, or at least a way to narrow it down. This can be considered one way to get a call trace

  • Add an exception in ofTrueTypeFont.cpp drawString()
  • Then compile Debug version of app (not sure this is important but did this anyway)
  • Then run app with valgrind:
void ofTrueTypeFont::drawString(const std::string &  c, float x, float y) const{
	if (!bLoadedOk){
		ofLogError("ofTrueTypeFont") << "drawString(): font not allocated";
		throw std::invalid_argument( "BAD FONT SEE ofTrueTypeFont.cpp" );
		return;
	}
	ofGetCurrentRenderer()->drawString(*this,c,x,y);
}

run:

make Debug
valgrind -v ./bin/project_debug

result:

[ error ] ofTrueTypeFont: drawString(): font not allocated
terminate called after throwing an instance of 'std::invalid_argument'
what():  BAD FONT SEE ofTrueTypeFont.cpp
[verbose] ofSignalHandler: Aborted
==66305== 
==66305== Process terminating with default action of signal 6 (SIGABRT): dumping core
==66305==    at 0x89EE34C: __pthread_kill_implementation (in /usr/lib/libc.so.6)
==66305==    by 0x89A14B7: raise (in /usr/lib/libc.so.6)
==66305==    by 0x898B5C5: abort (in /usr/lib/libc.so.6)
==66305==    by 0x86CF7ED: __gnu_cxx::__verbose_terminate_handler() [clone .cold] (vterminate.cc:95)
==66305==    by 0x86DBC4B: __cxxabiv1::__terminate(void (*)()) (eh_terminate.cc:48)
==66305==    by 0x86DBCB8: std::terminate() (eh_terminate.cc:58)
==66305==    by 0x86DBF5D: __cxa_throw (eh_throw.cc:95)
==66305==    by 0x5A9425: ofTrueTypeFont::drawString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, float, float) const (ofTrueTypeFont.cpp:1332)
==66305==    by 0x1F1DDA: onScreenButton::draw() (onScreenButton.h:62)
==66305==    by 0x2237E2: ofApp::drawControlScreen() (ofApp.cpp:1349)
==66305==    by 0x2230C1: ofApp::draw() (ofApp.cpp:1229)
==66305==    by 0x4CF3EC: ofBaseApp::draw(ofEventArgs&) (ofBaseApp.cpp:50)

show it shows me that I should start looking at ofApp.cpp:1349

great!

ah glad you sorted it, and thanks for sharing the solution!