Skip to main content
gamedev.net
🔒 Locked

wtf!?!?!?!?!?

Started by tHiSiSbOb Dec 6, 2002 at 3:30 PM 0 replies 200+ views
Original Post
tHiSiSbOb
tHiSiSbOb
O.k. I have a class that has a pointer to a structure. When I init the pointer it works in one program(DOS) but gives me an access violation In a windows prog?? Here is my code. defs:
      

#ifndef _defs_h_
#define _defs_h_



#include <windows.h>
#include <stdio.h>
#include <gl\gl.h>										// Header File For The OpenGL32 Library
#include <gl\glu.h>	



struct VERTEX

{
	float x;
	float y;
	float z;
	float R;
	float G;
	float B;
	float texx;
	float texy;
};


struct MD2_HEADER
{
   int magic; 
   int version; 
   int skinWidth; 
   int skinHeight; 
   int frameSize; 
   int numSkins; 
   int numVertices; 
   int numTexCoords; 
   int numTriangles; 
   int numGlCommands; 
   int numFrames; 
   int offsetSkins; 
   int offsetTexCoords; 
   int offsetTriangles; 
   int offsetFrames; 
   int offsetGlCommands; 
   int offsetEnd; 
};

struct MD2_VERTEX
{
   byte  vertex[3];
   byte lightNormalIndex;
};
struct MD2_FRAME
{
   float scale[3];
   float translate[3];
   char name[16];
   MD2_VERTEX verts[1];
};


class INFINITY
{
public:
	 void RenderVertexList(VERTEX * vertList,int numPrims);
	
	
};



typedef struct
{
   short vertex[3];
   short texture[3];
} MD2_TRIANGLE;





class MD2
{
public:
	MD2_HEADER header;
	MD2_FRAME *frames;
	MD2_TRIANGLE *triangles;
	 bool LoadMD2(char *fileName);
	void RenderMD2();

};
#endif
    
init: bool MD2::LoadMD2(char *fileName) { int i; FILE *filePointer; filePointer=fopen(fileName,"rb"); if(!filePointer) { return FALSE; } fread(&header,1,sizeof(MD2_HEADER),filePointer); if(header.numFrames<1) { // cout<<"FUCK"<,1,sizeof(MD2_TRIANGLE),filePointer); fseek(filePointer,header.offsetFrames,SEEK_SET); for(i=0;i[edited by - tHiSiSbOb on December 6, 2002 6:36:44 PM] [edited by - tHiSiSbOb on December 6, 2002 6:37:46 PM]
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
Kylotan
Kylotan
You do:

fread(&triangles...

but ''triangles'' is just a pointer in a struct. Which means you scribble over whatever comes after that pointer/struct in memory. You probably want to write to the memory that ''triangles'' points at, and therefore need something like:

fread(triangles...

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.