hi, i have a strange crash on windows (visual studio 2005 sp1) with the following code:
the strange thing is, do i comment out the copy of the bitmap buffer in the loop at the middle the crash does not occur. i checked everything twice, all indices are correct. i also tried the NeHe demo for freetype font loading for opengl rendering [1] with the cour.ttf file and the crash also occured there (using freetype 2.1.4). also strange is that the crash occurs at different character codes with different ttf files. the courier ttf crashes very early (around 144). please, if someone knows any workarounds let me know... -chris [1] http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=43 bool init_font_rendering() { // soon to be parameters std::string _font_file_name = std::string("C:/WINDOWS/fonts/cour.ttf");//consola.ttf");// unsigned _font_pixel_size = 12; unsigned _display_dpi_resolution = 96; FT_Library ft_lib; // initialize freetype if (FT_Init_FreeType(&ft_lib) != 0) { std::cout << "error initializing freetype library" << std::endl; return (false); } // load font face FT_Face ft_face; if (FT_New_Face(ft_lib, _font_file_name.c_str(), 0, &ft_face) != 0) { std::cout << "error loading font file (" << _font_file_name << ")" << std::endl; return (false); } // rendering the font bullshit into a texture if (FT_Set_Char_Size(ft_face, 0, _font_pixel_size << 6, 0, _display_dpi_resolution) != 0) { //if (FT_Set_Pixel_Sizes(ft_face, 0, _font_pixel_size) != 0) { std::cout << "error setting font sizes" << std::endl; return (false); } unsigned font_glyph_size_x = ft_face->size->metrics.max_advance >> 6; unsigned font_glyph_size_y = ft_face->size->metrics.height >> 6; unsigned font_tex_size_x = font_glyph_size_x * 16u; unsigned font_tex_size_y = font_glyph_size_y * 16u; unsigned char* font_tex = new unsigned char[font_tex_size_x * font_tex_size_y]; // clear texture background to black memset(font_tex, 0u, font_tex_size_x * font_tex_size_y); unsigned dst_x, dst_y; for (int i = 0; i < 256; ++i) { if(FT_Load_Glyph(ft_face, FT_Get_Char_Index(ft_face, i), FT_LOAD_DEFAULT)) { std::cout << "error loading glyph at char code: " << i << std::endl; } else { if (FT_Render_Glyph(ft_face->glyph, FT_RENDER_MODE_NORMAL)) { std::cout << "error rendering glyph at char code: " << i << std::endl; } FT_Bitmap& bitmap = ft_face->glyph->bitmap; dst_x = (i & 0x0F) * font_glyph_size_x; dst_y = (i >> 4) * font_glyph_size_y; //std::cout << i << " w: " << bitmap.width << "\th: " << bitmap.rows << "\tp: " << bitmap.pitch << std::endl; for (int dy = 0; dy < bitmap.rows; ++dy) { for (int dx = 0; dx < bitmap.width; ++dx) { unsigned src_off = dx + dy * bitmap.width; unsigned dst_off = (dst_x + dx) + (dst_y + dy) * font_tex_size_y; font_tex[dst_off] = bitmap.buffer[src_off]; } } } } // shutdown font face if (FT_Done_Face(ft_face) != 0) { std::cout << "error closing font face" << std::endl; return (false); } // shutfdown freetype if (FT_Done_FreeType(ft_lib) != 0) { std::cout << "error shutting down freetype library" << std::endl; } return (true); } -- Christopher Lux | | Bauhaus University Weimar | Faculty of Media - Virtual Reality Systems Group _______________________________________________ Freetype mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/freetype
