memononen / fontstash

Light-weight online font texture atlas builder
zlib License
688 stars 88 forks source link

Access violation on fons__getState #12

Closed davidtweaver closed 10 years ago

davidtweaver commented 10 years ago

Trying to incorporate the example code into a project, but when the software makes the call to fonsSetFont, I receive an access violation on fons__getState

I've included a sample of the code below

    struct FONScontext* fs = glfonsCreate(512, 512, FONS_ZERO_TOPLEFT);
int fontNormal = fonsAddFont(fs, "sans", "../DATA/Fonts/apercu-regular.ttf");
fonsSetFont(fs, fontNormal);
fonsSetSize(fs, 64.0f);
fonsDrawText(fs, dx, dy,text, NULL);
memononen commented 10 years ago

Are you checking the return value of fs? It should ne non-null.

davidtweaver commented 10 years ago

Hmm, you're right, it does appear to be null. Have I missed something important?

Thanks for your help by the way.

memononen commented 10 years ago

It can either fail if it cannot allocate memory or if it fails to create texture. Are you initializing OpenGL correctly? If you can run your code in debugger it would help a lot of you could step into the glfonsCreate() (and subsequent call to fonsCreateInternal()) and see where it errors out.

davidtweaver commented 10 years ago

I'm using GLee.h (which apparently doesn't need initialising but I'm calling GLeeInit() to be on the safe side)

Stepping through just provides an unhandled exception at return &stash->states[stash->nstates-1];

in fons__getState

it doesn't move forward from there

memononen commented 10 years ago

The problem happens arealier. During the init, can should step into glfonsCreate() and when in there, step into fonsCreateInternal() and let me know at which line the code exists?

belazaras commented 10 years ago

Hi there memononen, it's happening the same here, I followed the glfonsCreateInternal method but I didn't find the problem (I don't know how to use the debugger too well), here's a capture of the fs, I hope it helps, thanks for everything! error

memononen commented 10 years ago

The debug says that fs = NULL, means that glfonsCreate() failed. Looking at your code the reason it fails is that you have not initialized OpenGL, you have to do that before you call glfonsCreate(). Just put the initialization code after the GLFW window open code and everything should be fine.

belazaras commented 10 years ago

Lol, that's awesome man, it worked, thanks again!