Thank-you for the reply, I apologize for the incomplete sample - as I had sent it out without testing, while I was putting together a Makefile. The LoadFile function is completely different in the sample I sent compared to my actual Android application, and it turns out that my completed sample succeeds, but my Android app fails. The major difference between the two is the way that the input file is loaded. However I verify that my Android app correctly reads in the input file by performing a byte comparison between the original input file and a file that I write out consisting of the buffer that I had just read into.
Thanks for all the responses, I will continue to investigate, thanks!LD From: [email protected] Date: Thu, 8 Sep 2011 12:35:55 +0200 Subject: Re: [ft-devel] FT_New_Memory_Face crashes To: [email protected] CC: [email protected]; [email protected] Hi Louis, if I parse your sample code correctly, your LoadFile function does not allocate a memory buffer to read in the font file. Thus you overwrite memory big style. The declaration char buf[]; only declares a pointer to a character buffer. The pointer has an undefined value (address) and this is also where your data goes to. Thus your problem is not related to freetype library but more to a uncompleted transition from Java to bare bone C/C++ programming world. Quick Fix: : unsigned char *LoadFile( char * fileName, zip_uint64_t &fileSize ){ int MAX_FILE_SIZE = 10485760; unsigned char *buf = new char[MAX_FILE_SIZE]; FILE *inFile = fopen("fileName","rb"); fileSize = (zip_uint64_t)fread(buf, sizeof(unsigned char), MAX_FILE_SIZE, inFile); fclose(inFile); return buf; }Smart fix: first determine the actual file size with fseek / ftell prior to allocate the buffer for maximum size. Android devices are very memory limited. br Gernot 2011/9/7 Louis Desjardins <[email protected]> Thanks for your reply. I am still trying to get a successful Makefile going so I have not been able to test this standalone app yet, however in case it helps, I have attached the code that should provide the crash in the meanwhile. The main program is in Standalone.cpp and crashes within FT_New_Memory_Face. I have also provided a sample ttf and the freetype library that I am using with Android (though I have added various 'printfs' for debugging). Thank-you From: [email protected] Date: Wed, 7 Sep 2011 13:06:36 -0400 Subject: Re: [ft-devel] FT_New_Memory_Face crashes To: [email protected] CC: [email protected] It should be possible to create a self standing example that will compile on a Linux box. It might not have to be fully equivalent as long as it fails in the same way and aids in debugging Chris On Sep 7, 2011, at 12:23 PM, Louis Desjardins <[email protected]> wrote: I apologize, I made a copy\paste error when providing the sample, I have corrected it below as they are in fact the same buffers in the code I'm running. Unfortunately I cannot provide a complete standalone sample as I am working in the Android NDK. LD From: [email protected] To: [email protected] Date: Wed, 7 Sep 2011 03:47:26 -0400 Subject: RE: [ft-devel] FT_New_Memory_Face crashes In the code sample, FT_NEW_MEMORY_Face() is passed a different buffer from the one created by LoadFile(). From: [email protected] [mailto:[email protected]] On Behalf Of Louis Desjardins Sent: 07 September 2011 00:13 To: [email protected] Subject: [ft-devel] FT_New_Memory_Face crashes I have loaded an "arial.ttf" file (taken from my /Windows/Fonts folder) into memory, however passing this into FT_New_Memory_Face crashes (I have also tried other ttf files, and this function still crashes). Any clues as to what I might be doing wrong? Note that I am using Freetype with the Android NDK, so it is difficult to debug, however I find that eventually, the crash occurs within: FT_New_Memory_Face -> FT_Open_Face -> FT_Stream_ReadLong -> crashes at: if ( p ) { result = FT_NEXT_LONG( p ); //crashes here, in file ftstream.c, method FT_Stream_ReadLong } And below is my code: unsigned char *fontBuffer = LoadFile("arial.ttf"); zip_uint64_t fSize = GetFileSize("arial.ttf"); // I checked this, and it returns the correct size FT_Library library; FT_Face face; int error = FT_Init_FreeType( &library ); // I checked this, this step succeeds if( error != 0 ) printf("FT_Init_FreeType failed"); error = FT_New_Memory_Face( library, (FT_Byte*)fontBuffer, fSize, 0, &face ); _______________________________________________ Freetype-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/freetype-devel _______________________________________________ Freetype-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/freetype-devel
_______________________________________________ Freetype-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/freetype-devel
