   freetype2 opengl access violation error...need help
  I've been trying to get truetype fonts to show up in my opengl project using the freetype2 lib. The project compiles ok but I keep getting an access violation error on the line with  FT_GlyphSlot slot = face->glyph; in the function drawText; When i turn off the parts resposible for fonts all renders ok so I'm only posting the truetype stuff. Am I messing up something with the order of defining FT_Face face that its causing the violation?//////////////////////////////// includes#include <windows.h>#include <gl/gl3.h>#include <gl/glu.h>#include <stdio.h>#include <iostream>#include <vector>#include <fstream>#include <string>#include <soil/SOIL.h>#include <math.h>#include "render.h"#include "component.h"#include "inputs.h"#include <ft2build.h>#include <ft2build.h>#include FT_FREETYPE_H///////////////////////////////// defined before main loop //FT_Library  library;FT_Face face;   GLuint texture;int nextpoweroftwo(int x){double logbase2 = log(float(x)) / log(float(2));//return round(pow(2,ceil(logbase2)));return (int)((pow(2,ceil(logbase2)))+0.5);}void drawFillRectTextured (float x, float y, float width, float height) {    glBegin (GL_QUADS);   glTexCoord2f (0.0f,0.0f); glVertex2f (x,y);   glTexCoord2f (1.0f, 0.0f);    glVertex2f (x+width, y);   glTexCoord2f (1.0f, 1.0f);  glVertex2f (x+width, y+height);   glTexCoord2f (0.0f, 1.0f);   glVertex2f (x, y+height);    glEnd (); }void drawBitmap (FT_Bitmap * bitmap, FT_Int left, FT_Int top) {    int width = nextpoweroftwo( bitmap->width );    int height = nextpoweroftwo( bitmap->rows );   GLubyte* buffer = new GLubyte[ 2 * width * height];    for(int j=0; j <height;j++) {    for(int i=0; i < width; i++){    buffer[2*(i+j*width)]= buffer[2*(i+j*width)+1] =(i>=bitmap->width || j>=bitmap->rows) ?    0 : bitmap->buffer;    }    }    glBindTexture( GL_TEXTURE_2D, texture ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );   glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );   glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, buffer );delete [] buffer;//setColor(GREEN);glEnable (GL_TEXTURE_2D);drawFillRectTextured(left, top, bitmap-&gt;width, bitmap-&gt;rows);glDisable (GL_TEXTURE_2D); }  void drawText (string text, FT_Face face, int pen_x, int pen_y) {  int error;  FT_GlyphSlot slot = face-&gt;glyph;    for (unsigned int n=0;n&lt;text.length();n++) {   error = FT_Load_Char( face, 't', FT_LOAD_RENDER );    if ( error )   continue;   drawBitmap (&slot-&gt;bitmap, slot-&gt;bitmap_left + pen_x, slot-&gt;bitmap_top + pen_y); pen_x += slot-&gt;advance.x &gt;&gt; 6;   pen_y += slot-&gt;advance.y &gt;&gt; 6;    } } void loadFTFonts () {    int error;   error = FT_New_Face ( library, "./arial.ttf", 0, &face );   if (error == FT_Err_Unknown_File_Format) {    //    cerr &lt;&lt; "Font isn't in the correct format." &lt;&lt; endl;   //exit (1);    } else if (error) {   //cerr &lt;&lt; "Error opening font." &lt;&lt; endl;   //exit (1);    }   error = FT_Set_Pixel_Sizes( face, /* handle to face object */    0, /* pixel_width */   18 );    if (error) {  // cerr &lt;&lt; "FT_Set_Pixel_Sizes failed to set the pixel sizes!" &lt;&lt; endl;  // exit (1);    } }////////////////////////////////////////// inside my initiliazation functionvoid init(){loadFTFonts ();…. setting up threads  &  opengl window }//////////////////////////////////////////// main engine drawing loop void mainloop(){  drawText ("test the text", face,  10,  20);  draw(); };/////////////////////////////////////////////////////////////////// setting up winmain and initializing init() the main loop#ifdef _DEBUGint WINAPI WinMain(HINSTANCE i, HINSTANCE p, LPSTR cmd, int n)#elseint WinMainCRTStartup()#endif{ PIXELFORMATDESCRIPTOR pfd; HWND hwnd; HDC hdc; int  pixelFormat;#ifdef FULLSCREEN DEVMODE dmScreenSettings;    // Device Mode#endif#ifndef _DEBUG HINSTANCE i = GetModuleHandle(NULL);#endif /* init the pixelformat descriptor */  RtlZeroMemory(&pfd,sizeof(PIXELFORMATDESCRIPTOR));    // Clear the struct pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR);    // Size  pfd.nVersion=1;    // Version pfd.dwFlags=PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;  // Selected flags pfd.iPixelType=PFD_TYPE_RGBA;// Pixelformat pfd.cColorBits=32; // Pixel depth pfd.cDepthBits=16; // Zbuffer depth pfd.iLayerType=PFD_MAIN_PLANE;    // Place the pixelformat &#111;n the main plane#ifdef FULLSCREEN /* init the resolution change settings */ RtlZeroMemory(&dmScreenSettings,sizeof(dmScreenSettings)); // Clear the struct dmScreenSettings.dmSize=sizeof(dmScreenSettings);// Size Of The Devmode Structure dmScreenSettings.dmPelsWidth   = 640;  // Selected Screen Width dmScreenSettings.dmPelsHeight  = 480;  // Selected Screen Height dmScreenSettings.dmBitsPerPel  = 32;   // Selected Bits Per Pixel dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;  // Notify which fields we have used  if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) return 0;#endif /* setup the window handle */ hwnd=CreateWindowEx(WS_EX_TOOLWINDOW, L"STATIC", L"blipblop", WS_POPUP|WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, 0, 0, 800, 600, 0, 0, i, 0);  /* select the pixel format for the current window */  hdc = GetDC(hwnd); pixelFormat = ChoosePixelFormat(hdc, &pfd); SetPixelFormat(hdc, pixelFormat, &pfd); wglMakeCurrent(hdc, wglCreateContext(hdc)); /* cursor be gone */ SetCursor(0);  init(); /* loop until escape is pressed all normal windows messages are ignored */ while (!GetAsyncKeyState(VK_ESCAPE)) {   mainloop();    // nifty effects here   SwapBuffers(hdc);   // display the cool stuff }    return 0;  // exit to OS}// clean upI've been stuck trying to get my head around implementing freetype for the past 2 days. The include paths and libs for freetype are setup so they don't give off any errors.