Help With Ttf Font And Sdl_rwops


GP2X_Coder

Member
Joined
May 17, 2006
Messages
220
Age
52
Location
USA
Website
mysite.verizon.net
Could someone please help and tell me what in the world is wrong with this code I get no errors from TTF_GetError() but SDL returns Fatal signal: Segmentation Fault (SDL Parachute Deployed)

Code:
size_t OpenDataFile( std::fstream *File, const char *DirectoryPath )
{
	// If loaded from a directory
	// Open the data file
	File->open( DirectoryPath, std::ios::in | std::ios::binary);
		return GetTotalFileSize( DirectoryPath );
	
	// Not found return zero
	return 0;
}


void SDLFONT::Create( const char *FontPath, unsigned int FontSize )
{		
	// Now lest open our data file
	std::fstream File;
	int fsize = OpenDataFile( &File, FontPath );
	if( fsize == 0 )
		printlog( "\nCouldn't Load Font: %s ", FontPath );
		
	// Create a buffer to load in the file with	
	char *buffer = new char [ fsize ];
	File.read( buffer, fsize );
	
	// Read in the buffer and the total file size into rwops
	SDL_RWops *wops = SDL_RWFromMem( buffer, fsize );
	if( wops == NULL )
		printlog( "\nCouldn't Load Font(NULL SDL_RWops): %s ", FontPath );
		
	// Load in the font from memory  
	Font = TTF_OpenFontRW( wops, 0, FontSize );
	if( !Font ) 
		printlog( "\tTTF_OpenFont: %s", TTF_GetError() );
		
	// Finished with the buffer delete it
	if( buffer )
	{
		delete [] buffer;
		buffer = NULL;
	}
	
	// Close the file we opened
	File.close();
	
	// Free the image we have in memory
	if( wops )
	{
		SDL_FreeRW( wops );
		wops = NULL;
	}
}
 
Back
Top