We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 81

Summary: TTF_OpenFontRW( ... ) fails on Windows while working on Linux.
Product: SDL_ttf Reporter: Klaus Blindert <klaus.blindert>
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: mikael_miffe_eriksson
Version: unspecified   
Hardware: All   
OS: All   

Description Klaus Blindert 2006-01-24 20:21:26 UTC
First: Thanks for this nice library.
We are going to use it in our game engine: www.fifengine.de
But now to the bug(s).

This is perfectly valid code on Linux.
But on Windows it throughs the second exception,
when the font file exists.

SDL_RWops* rwops = SDL_RWFromFile(filename.c_str(),"r");

if( rwops ) {
	mFont = TTF_OpenFontRW(rwops,1,size);
} else {
	throw GCN_EXCEPTION("Error loading file:"+filename +
		" SDL_Error: "+std::string(SDL_GetError()));
};

if (mFont == NULL) {
	throw GCN_EXCEPTION("Error loading file: "+filename +
		" TTF_Error: "+std::string(TTF_GetError()));
}

We introduced RWops, for the following reason:
The following snippet works on windows and linux,
but SEGFAULTS when the file is nonexistent. This can be worked around,
but is still a bug.

mFont = TTF_OpenFont(filename.c_str(),size);

if (mFont == NULL) {
	throw GCN_EXCEPTION("Error loading file: "+filename +
		" TTF_Error: "+std::string(TTF_GetError()));
}

Since we use a virtual filesystem, it would be good, if SDL_TTF works
with RWops together.

I didn't find anything related. It's too late today to dive into
the TTF sourcecode, but I will assist in figuring the problem out.
I think, we'll be able to work around the bug ... 
Library version is 2.0.7

Greetings, Klaus (aka Phoku)
Comment 1 Mikael Eriksson 2006-01-27 03:46:04 UTC
When creating the RWops, you have to specifiy the mode as "rb", not just "r".

This is also safe on linux.
Comment 2 Sam Lantinga 2006-01-27 03:54:44 UTC
Good point, thanks Mikael!
Comment 3 Ryan C. Gordon 2006-01-27 11:23:24 UTC
Setting Sam as "QA Contact" on all bugs (even resolved ones) so he'll definitely be in the loop to any further discussion here about SDL.

--ryan.