   GL exception, abnormal program termination
  Hi. I''m currently writing a model importer augmented with a maxscript to export 3dsmax geometry data into a binary file.I saw the linked list acticle "Using Linked Lists to Represent Game Objects" on the gamedev home, and decided to give it a try. The bug is as follows. I initialize a global WORLD pointer. In InitGL() I allocate memory to it and call its load_world method. Load world opens an ifstream for the geometry data. The data goes into two arrays and I build linked lists from those and generate glLists from those. I use an errorlog to verify that the file has been properly read, the linked lists have been properly created and contain the correct number of nodes. InitGL() returns. When glClear() is called in glDrawscene, the executable exits, without error.I''m currently using borland commandline compiler 5.5. I single stepped through the source. When the debugger comes upon glClear()  the dubber give the error "Stopped on Exception Throw".If I do not call load_world() in InitGL() the program runs without error.I''ve included the the file that contains load_world()   class POLYGON_LIST{public:POLYGON_LIST();~POLYGON_LIST();POLYGON* addPolygon(POINT3f, POINT3f, POINT3f);void genLists();void draw();POLYGON* head;POLYGON* tail;};POLYGON_LIST::POLYGON_LIST(){this->head = NULL;this->tail = NULL;}POLYGON_LIST::~POLYGON_LIST(){}void POLYGON_LIST::draw(){}void POLYGON_LIST::genLists(){}POLYGON* POLYGON_LIST::addPolygon(POINT3f pt_1, POINT3f pt_2, POINT3f pt_3){if(head== NULL && tail==NULL){tail = head = new POLYGON(pt_1, pt_2, pt_3);tail->next = NULL;}else{tail->next= new POLYGON(pt_1, pt_2, pt_3);tail = tail->next;tail->next = NULL;}return head;}class OBJECT{public:OBJECT();~OBJECT();void draw();void genLists(void);OBJECT* next;POLYGON_LIST* polygon_list;GLuint draw_list;};OBJECT::OBJECT(){next = NULL;polygon_list = new POLYGON_LIST;}OBJECT::~OBJECT(){delete polygon_list;}void OBJECT::genLists(){draw_list=glGenLists(1);glNewList(draw_list,GL_COMPILE);glBegin(GL_QUADS);/*Loop for each polygon in the list*/for(POLYGON* poly_cur= polygon_list->head; poly_cur!=polygon_list->tail; poly_cur=poly_cur->next){/*Loop for each vertex*/for(int i=0; i<3; i++){glVertex3f(poly_cur->points[i].x, poly_cur->points[i].y ,poly_cur->points[i].z);}}glEnd();glEndList();}void OBJECT::draw(){glCallList(this->draw_list);}class OBJECT_LIST{public:OBJECT_LIST();~OBJECT_LIST();OBJECT* addObject();void genLists();void draw();OBJECT* head;OBJECT* tail;};OBJECT_LIST::OBJECT_LIST(){head = NULL;tail = NULL;}OBJECT_LIST::~OBJECT_LIST(){}void OBJECT_LIST::draw(){/*Loop for each object in the list*/for(OBJECT* obj_cur= head; obj_cur!=tail; obj_cur=obj_cur->next){obj_cur->draw();}}void OBJECT_LIST::genLists(){/*Loop for each object in the list*/for(OBJECT* obj_cur= head; obj_cur!=tail; obj_cur=obj_cur->next){obj_cur->genLists();}}OBJECT* OBJECT_LIST::addObject(){if(head==NULL && tail==NULL){tail = head = new OBJECT;tail->next = NULL;}else{tail =  new OBJECT;tail = tail->next;tail->next = NULL;}return tail;}class WORLD{public:WORLD();~WORLD();void load_world(char*);CAMERA w_camera;void draw(void);void genLists(void);OBJECT_LIST* object_list;GLuint* texture_head;GLuint* texture_tail;//ofstream errlog;};WORLD::WORLD(){object_list = new OBJECT_LIST;//errlog.open ("ERRORLOG.txt", ios::out | ios::trunc);}WORLD::~WORLD(){delete object_list;}void WORLD::load_world(char* filename){long* header[2];char* file_section = new char[128];long_num long_verts;long_num long_polys;ifstream file;file.open (filename, ios::in | ios::binary);if(!file.is_open()){MessageBox(NULL, "File data/testmesh.dat could not be opened","SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);return;}ofstream errlog;errlog.open ("ERRORLOG.txt", ios::out | ios::trunc);errlog << "Created file streams\n";errlog.flush();errlog << "assigning *num_vertices\n";errlog.flush();long* num_vertices;file.read((char*)num_vertices, sizeof(long));errlog << "num_vertices assigned\n";errlog.flush();errlog << "Read number of vertices " << *num_vertices << "\n";errlog.flush();long* num_polygons;file.read((char*)num_polygons, sizeof(long));errlog << "Read number of polygons "<< *num_polygons << "\n";errlog.flush();file.read(file_section, sizeof(char)*8);errlog<<"read file section "<< file_section << "\n";errlog.flush();file.read(file_section, sizeof(char)*1);/*Allocate memory to store polygons in*/float* buf_vertices = new float[(*num_vertices)*3];errlog<<"assigned memory "<< (*num_vertices)*3*4 << "bytes\n";errlog.flush();long* buf_polygons = new long[(*num_polygons)*3];errlog<<"assigned memory "<< (*num_polygons)*3*4 << "bytes\n";errlog.flush();errlog<<"adding an object\n";errlog.flush();object_list->addObject();errlog<<"added object to world \n";errlog.flush();errlog<<"reading vertices \n";errlog.flush();/*Read vertices*/char* chunk= new char[32];for(int i=0;  i<*num_vertices*3; i++){file.read((char*)(&buf_vertices[i]), 4);errlog << *(buf_vertices+i) <<"\n";errlog.flush();}delete chunk;errlog<<"done  \n";errlog.flush();file.read(file_section, sizeof(char)*7);errlog<<"read file section "<< file_section << "\n";errlog.flush();file.read(file_section, sizeof(char)*1);errlog<<"readingpolygons \n";errlog.flush();/*Read polygons */for(int i=0; i<*num_polygons*3; i++){file.read((char*)(&buf_polygons[i]), sizeof(long));errlog << *(buf_polygons+i) <<"\n";errlog.flush();}errlog<<"done  \n";errlog.flush();errlog<<"building linked list  \n";errlog.flush();for(int i=0; i<(*num_polygons*3); i+=3){POINT3f pt_1(buf_vertices[buf_polygons[i+0]+0],buf_vertices[buf_polygons[i+0]+1],buf_vertices[buf_polygons[i+0]+2]);POINT3f pt_2(buf_vertices[buf_polygons[i+1]+0],buf_vertices[buf_polygons[i+1]+1],buf_vertices[buf_polygons[i+1]+2]);POINT3f pt_3(buf_vertices[buf_polygons[i+2]+0],buf_vertices[buf_polygons[i+2]+1],buf_vertices[buf_polygons[i+2]+2]);object_list->tail->polygon_list->addPolygon(pt_1, pt_2, pt_3);errlog<<"\tadded polygon"<<i/3<<"\n";errlog.flush();}errlog<<"done \n";errlog.flush();errlog<<"Generating glLists  \n";errlog.flush();object_list->genLists();errlog<<"Successfully Generated glLists  \n";errlog.flush();delete buf_vertices;   delete buf_polygons;errlog<<"finished loading "<<filename<<"\n";errlog.flush();errlog<<"verifying load "<<filename<<"\n";errlog.flush();int i=0;for(POLYGON* poly_cur=object_list->tail->polygon_list->head;  poly_cur!=NULL; poly_cur=poly_cur->next){i++;}errlog<<"number of polygons loaded "<<i<<"\n";errlog.flush();if(i==*num_polygons){errlog<<"load verification succeded \n";errlog.flush();}//file.close();//errlog.close();   }void WORLD::genLists(void){object_list->genLists();}void WORLD::draw(void){object_list->draw();}WORLD HAS_An OBJECT_LIST which HAS OBJECTs which HAS_A POLYGON_LIST which HAS POLYGONs.I''m resusing previous code for the POLYGON and POINT3f classes. They are known to work.Thankyou in advance. 
  when u cal glClear()  do u specify wat u want to clear as parameters ?for example if u wana clear the color buffer and the depth buffer you callglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ;  Well, here''s one error in load_world:long* num_vertices;file.read((char*)num_vertices, sizeof(long));  You declare a pointer, but never allocate memory for it to point to, so it points to a random locations.  You then read data from a file into this random location.You''re also mixing new[] and delete.  When you call operator new[] you must    call operator delete[].Enigma. ;  I''m usingglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);to be exact.However, I believe the problem to be pointer/memory related as the program does not crash if loadworld is not called. ;  Thank you so much Enigma. I properly allocated and deleted it, and now the program runs without crashing.  Now the only problem is that the geometry isnt displayed  But I''ll save that for another thread if I still cant figure it out in a week.Thankyou again. 