rougier / freetype-gl

OpenGL text using one vertex buffer, one texture and FreeType
Other
1.65k stars 266 forks source link

Bug in texture_font_load_glyphs #207

Open ltqsoft opened 5 years ago

ltqsoft commented 5 years ago

Program crashed with access violation error when I set texture atlas depth to 3, it worked fine with depth=1. The other depth settings are yet to be checked so I don't know it also works or not.

rougier commented 5 years ago

Do you have more information, like a working/non working example ?

ltqsoft commented 5 years ago

Here is my example code:

include "freetype-gl.h"

include

define ALLCHARS "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+| ,./<>?[]{}"

int main() { texture_atlas_t atlas = texture_atlas_new(512, 512, 3); texture_font_t font = texture_font_new_from_file(atlas, 32, "Arial.ttf"); font->rendermode = RENDER_SIGNED_DISTANCE_FIELD; printf("Loaded %d glyphs\n", texture_font_load_glyphs(font, ALLCHARS)); getchar(); }

I built the project without using cmake this time (just manually add source files), and at the second time the exception has been thrown at a different line. If those works on your machine, may be I should rebuild FreeType, or I did messed something up with source files.

rougier commented 5 years ago

Do you know which line is faulty?

ltqsoft commented 5 years ago

The program stopped at texture_atlas.c, line 98. And here are some content in my own source file, is it different?

94 for( i=0; i<height; ++i ) 95 { 96 memcpy( self->data+((y+i)self->width + x ) charsize depth, 97 data + (istride) charsize, width charsize * depth ); 98 }

rougier commented 5 years ago

From these information it is difficult to identify the problem. You should print all information (x,y,i,charsize,depth,etc.) to see if there's weird values.

ltqsoft commented 5 years ago

I think there's a problem with loading the NULL glyph, if I comment it out, the program runs successfully (but I yet don't know if it works correctly).

rougier commented 5 years ago

Why do you get a NULL glyph?

ltqsoft commented 5 years ago

Oops, I mean the glyph represent the NULL character ('\0'), it was loaded first of all by the texture_font_init(...) function.

rougier commented 5 years ago

Can you track (e.g. using printf) what is the faulty line?