FTGL crash when exiting program

Member
Posts: 257
Joined: 2004.06
Post: #1
Has anyone experienced crashes when exiting an app using FTGL? I'm running this under 10.5 with a slightly tweaked version of the source so that it compiles on 10.5 and all I'm doing is creating a font and rendering some text. It's driving me rather batty Wacko I'm about set to figure out how to just use FreeType directly.

The brains and fingers behind Malarkey Software (plus caretaker of the world's two brattiest felines).
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
The chance anyone can tell you anything without a) a description of the modifications you made to the source, and b) a crash log, is minimal. Even if you have the original author sitting 2m to your right. Which I do.
Quote this message in a reply
Member
Posts: 257
Joined: 2004.06
Post: #3
Doh! Oh yeah, huh. Sorry, I've been spending way too much time trying to figure this out. Anyway, the tweak I made was to line 9 of FTVectoriser.cpp. The original line was:
typedef GLvoid (*GLUTesselatorFunction)(...);

which caused compile errors under Leopard so I changed it to:
typedef GLvoid (*GLUTesselatorFunction)();

As for the crash, as far as I can tell, FreeType seems to die as FTGL tears it down. I've managed to get the FTGL demo up and running but there's no crashes there. This is the relevant bit from the crash log:

Code:
Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x000000000000028b
Crashed Thread:  0

Thread 0 Crashed:
0   ...y.ChemicalBonds_CocoaOpenGL    0x000b91cd ft_mem_free + 13 (ftutil.c:171)
1   ...y.ChemicalBonds_CocoaOpenGL    0x000bbd1d FT_Remove_Module + 317 (ftobjs.c:3229)
2   ...y.ChemicalBonds_CocoaOpenGL    0x000bbf93 FT_Done_Library + 195 (ftobjs.c:3824)
3   ...y.ChemicalBonds_CocoaOpenGL    0x000b8ad8 FT_Done_FreeType + 24 (ftinit.c:156)
4   ...y.ChemicalBonds_CocoaOpenGL    0x00107fa6 FTLibrary::~FTLibrary() + 26 (FTLibrary.cpp:17)
5   libSystem.B.dylib                 0x9171f53c __cxa_finalize + 241
6   libSystem.B.dylib                 0x9171f430 exit + 33
7   com.apple.AppKit                  0x93fd1fec -[NSApplication terminate:] + 772
8   com.apple.AppKit                  0x93ef2e56 -[NSApplication sendAction:to:from:] + 112
9   com.apple.AppKit                  0x93fa17cc -[NSMenu performActionForItemAtIndex:] + 493
10  com.apple.AppKit                  0x93fa14d1 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 220
11  com.apple.AppKit                  0x93fa1157 -[NSMenu performKeyEquivalent:] + 866
12  com.apple.AppKit                  0x93f9f9fd -[NSApplication _handleKeyEquivalent:] + 492
13  com.apple.AppKit                  0x93ebcb36 -[NSApplication sendEvent:] + 3838
14  com.apple.AppKit                  0x93e1a0f9 -[NSApplication run] + 847
15  com.apple.AppKit                  0x93de730a NSApplicationMain + 574
16  ...y.ChemicalBonds_CocoaOpenGL    0x00001e46 start + 54

At this point, all I'm doing is creating a new instance of a FTGLTextureFont object and then quitting the application. I guess next on my list of things to do is check the FTGL source code and see what it's doing with the FreeType library and create a standalone project that basically consists of creating a FTGLTextureFont and make sure it's not my OpenGL code.

The brains and fingers behind Malarkey Software (plus caretaker of the world's two brattiest felines).
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
Well, you've got a global by-value FTLibrary object, and you're crashing in its destructor. That suggests that something that it uses has already been destroyed earlier in the shutdown process. C++ static constructors and destructors are a bitch, and very, very rarely worth the trouble.

I'd recommend you make that global a pointer, new it at the appropriate moment at startup, and never delete it Wink
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #5
OneSadCookie Wrote:The chance anyone can tell you anything without a) a description of the modifications you made to the source, and b) a crash log, is minimal. Even if you have the original author sitting 2m to your right. Which I do.

H-how did you manage that?Blink

- Lincoln Green
http://www.binkworks.com/
Quote this message in a reply
Moderator
Posts: 452
Joined: 2008.04
Post: #6
Hairball183 Wrote:H-how did you manage that?Blink

Even programmers have to sit somewhere! Maybe there was no other seat left on the bus except for the one next to OSC. Rasp

;D
Quote this message in a reply
Member
Posts: 257
Joined: 2004.06
Post: #7
OneSadCookie Wrote:Well, you've got a global by-value FTLibrary object, and you're crashing in its destructor. That suggests that something that it uses has already been destroyed earlier in the shutdown process. C++ static constructors and destructors are a bitch, and very, very rarely worth the trouble.

I'd recommend you make that global a pointer, new it at the appropriate moment at startup, and never delete it Wink

Probably not a bad idea at this point. Wouldn't that leak memory, though? ;p

So as an experiment, I created a test project that incorporates FTGL and just creating a new instance of a FTGLTextureFont object and then immediately deleting it causes a crash. So I guess once I create an FTFont object, I should never delete it??? Wacko That seems rather broken to me.

The brains and fingers behind Malarkey Software (plus caretaker of the world's two brattiest felines).
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
Malarkey Wrote:Probably not a bad idea at this point. Wouldn't that leak memory, though? ;p

I was assuming this object gets created once at startup and destroyed (currently) at shutdown... is that not the case?
Quote this message in a reply
Member
Posts: 257
Joined: 2004.06
Post: #9
OneSadCookie Wrote:I was assuming this object gets created once at startup and destroyed (currently) at shutdown... is that not the case?

Sorry, I should've been more clear. The global by-value FTLibrary object is in the FTGL source code. It's not something I create and destroy. The only thing I'm creating is a FTGLTextureFont object which (I think) causes an instance of FTLibrary to be created via a singleton design pattern. So literally, having

Code:
FTGLTextureFont* font;

...

foo::foo()
{
    FTGLTextureFont* font = new FTGLTextureFont("some font somewhere");
}

causes my app to crash when I'm quitting so I'm rather perplexed by this. In fact, after further experimentation with a test project, where FTGL will crash and the kind of code that will crash it is rather inconsistent.

So as I mentioned earlier, I created a test project that all it does is create an instance of FTGLTextureFont. Quitting the app without deleting this object produces no crash on exit. However, immediately deleting the object does cause a crash.

The other thing I discovered is that by calling FTLibrary::Instance to set up the FTLibrary singleton, I can't do much else since calling simple functions like FaceSize() causes a crash.

I also did some Google searches for "FTGL Leopard" but didn't come up with anything useful. Maybe I should install 10.4 on an external drive and build the FTGL libraries there. Blink I think from my original post, I was just looking for people running 10.5 that are using FTGL and if any were found, if they had any problems with it.

The brains and fingers behind Malarkey Software (plus caretaker of the world's two brattiest felines).
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How do I flip upside down fonts in FTGL mr5z 4 510 Mar 3, 2014 03:36 PM
Last Post: JustinFic
  Xcode and FTGL hiddenspring81 7 5,411 Oct 10, 2013 03:00 PM
Last Post: ardowz
  Anyone run into this problem with FTGL? wadesworld 1 2,898 Apr 21, 2009 02:19 PM
Last Post: Oddity007
  OpenGL full screen mode leaves garbage on screen when exiting app Malarkey 5 4,937 Nov 19, 2008 12:51 PM
Last Post: Malarkey
  More Freetype/FTGL trouble Fenris 33 16,374 Sep 15, 2006 06:27 AM
Last Post: TomorrowPlusX