-
Describe the bug STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges)
{
stbtt_fontinfo info;
int i,j,n, return_value = 1;
//stbrp_context *context = (stbrp_context *) spc->pack_info;
stbrp_rect *rects;
// <---- spc->pixels memory is readable correctly, and zeroed as expected
// flag all characters as NOT packed
for (i=0; i < num_ranges; ++i)
for (j=0; j < ranges[i].num_chars; ++j)
ranges[i].chardata_for_range[j].x0 =
ranges[i].chardata_for_range[j].y0 =
ranges[i].chardata_for_range[j].x1 =
ranges[i].chardata_for_range[j].y1 = 0;
// <---- spc->pixels memory is not accessible anymore
n = 0; The line that crashes with SIGSEGV is at #3192 result->pixels[j*result->stride + i] = (unsigned char) m; Code in between this line, and the previously mentioned for loop, works correctly without crashing. To Reproduce
Expected behavior |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 2 replies
-
The loop in question only processes |
Beta Was this translation helpful? Give feedback.
-
As mentioned on "steps to reproduce", I'm using As said, the value for first is |
Beta Was this translation helpful? Give feedback.
-
I gathered a bit more data. |
Beta Was this translation helpful? Give feedback.
-
I can only guess because you're not actually showing YOUR code which is where the bug lies. You pass in |
Beta Was this translation helpful? Give feedback.
-
Been trying to figure out how to use As far as my understanding reaches (first year into programming) this data structure contains information that is stored in the font file itself? Is there existing documentation somewhere about this that I missed? |
Beta Was this translation helpful? Give feedback.
-
That worked, thank you. I always fail at the smallest things possible 😔 Goal is to use this in a game engine, but such engine doesn't render quads, and also asking for render calls from the virtual machine overcomplicates things by a million (its not coded to allow that at all). How do you access the packed bitmap buffer, after the call to PackFontRanges has ended? |
Beta Was this translation helpful? Give feedback.
Been trying to figure out how to use
stb_truetype.h
to create a font bitmap atlas.This is the code I have so far:
https://gist.github.com/heysokam/0270e3bcc36c6c0d537b476d5862dbc2#file-fontatlas-c-L291
As you can see, I haven't generated the
chardata_for_range
array, I just created an emptystbtt_packedchar
struct, since I didn't know what to do with it.As far as my understanding reaches (first year into programming) this data structure contains information that is stored in the font file itself?
But I don't know how to generate such data.
Is there existing documentation somewhere about this that I missed?
If not, how can one create the required array?