Archived

This topic is now archived and is closed to further replies.

Access violation

This topic is 6011 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I made a class for meshes, called CMesh, and I stuck it inside the public section of my main application class with this statement: CMesh *m_pSphere; Then, within a function of my main application class, I do this: m_pSphere->InitDeviceObjects( m_pd3dDevice, ".\\Meshes\\sphere2.x" ); Within InitDeviceObjects, I copied the code from the Meshes example in the DX8 tutorials. It gives me an access violation crash each time. My mesh class declares the mesh involved variables (copied from the tutorial but put into a class) like this: LPD3DXMESH m_pMesh; D3DMATERIAL8* m_pMeshMaterials; LPDIRECT3DTEXTURE8* m_pMeshTextures; DWORD m_dwNumMaterials; The first thing I noticed was that my classes constructor was not being called, the second thing I noticed was that when I stuck a statement like "m_pMesh = NULL;" inside of InitDeviceObjects, I get the same access violation. So its not letting me access the class member variables from within the class.... how can this be? Is something not being initialized correctly? I don''t understand why the constructor isn''t called, makes no sense! Thanks, Tom

Share this post


Link to post
Share on other sites
Well, I''m not sure if the class is really global... The main application class is instantiated inside WinMain. But, the include for the header file, which has the CMesh *m_pSphere line, is outside of anything. So are you saying when it includes the file, the constructor is trying to be called there but it can''t? It seems like the constructor should be called when the class that is outside it is instantiated.

As for initializing m_pSphere, as I said the constructor is not being called, and thats where it is supposed to be initalized. Other than that theres no initalization required.

The main point I don''t understand is that fact that I get an access violation when accessing member variables of a class from within a function of the class, makes no sense. Of course, its not a syntax error, so I guess the variables must be pointing to nothing. In the debugger they have addresses, but it crashes when u try to assign to them. So somehow they aren''t being created properly, does anyone have experience with this?

Tom

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Your m_pSphere is a pointer to a CMesh and not an instance. To instantiate add this line

m_pShpere = new CMesh();

somewhere before you call any method of m_pShpere the first time.
BTW: do not forget to release the memory when your prog finishes (left as an exercise for the reader

Bjørn.

Share this post


Link to post
Share on other sites