• Advertisement

Archived

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

Pointer error/problem

This topic is 5846 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 have a little problem with pointers and I can''t figure out what I''m doing wrong the classes and structures involved are included below. I define an object of the class cObject (object) and when I execute: object.VB->CopyObjectInto(vector); I get an error that the memory couldn''t be "read". but when I would excecute it with an object of the class cVertexbuffer (VB) like: VB->CopyObjectInto(vector); it does work...so what is done wrong with my cObject class (I assume the error is in that class) that ''causes the error? Chris ================================================================ struct sVector { double x, y, z; }; struct TLVertex { FLOAT x, y, z, rhw; D3DCOLOR Specular, Diffuse; FLOAT tu, tv; }; class cObject { public: cVertexBuffer *VB; cObject *next; // Points to the next object in the list. cObject(); }; cObject::cObject() { VB = new (cVertexBuffer); } class cVertexBuffer { public: TLVertex *vtx; LPDIRECT3DVERTEXBUFFER8 pVB; int CopyObjectInto(sVector vertex[4]); }; int cVertexBuffer::CopyObjectInto(sVector vertex[4]) { int i; pVB->Lock(0, 0, (BYTE**)&vtx, 0) for(i = 0; i < 4; i++) { vtx.x = vertex[i].x; vtx[i].y = vertex[i].y; vtx[i].z = vertex[i].z; } pVB->Unlock(); return 0; }

Share this post


Link to post
Share on other sites
Advertisement
If you''ve included all the code here, you''re missing the initialization of your vertex buffer. You''re almost there, though- just add a constructor to cVertexBuffer and have it do the CreateVertexBuffer() call.

Alternately, you could have CopyObjectInto() create the VB, but either way you should probably have a constructor to zero out your pointer members. If nothing else it makes debugging easier.

--
Eric

Share this post


Link to post
Share on other sites

  • Advertisement