Jump to content
  • Advertisement

Archived

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

shakazed

Ops! I did it again...

This topic is 5837 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

Could use some help in this matter. I´ve defined a struct inside a class, as private. Actually it´s the vertex format structure. Then I declared an instance? of it. Something like this
            

class DX
{
public.
...
...
...

private:
struct CUSTOMVERTEX
{
float x,y,z;
D3DCOLOR diffuse;
};

CUSTOMVERTEX m_sVertex[2];

}  

  
Then using a member function I want to fill this structure with vertex data, like this:
                    
void cDGfx::D3DTriangle(void) 
{
	//Fill out the structure with vertex data, x,y,z and color

	m_sVertex[0].x = 150.0f;
	m_sVertex[0].y = 50.0f;
	m_sVertex[0].z = 1.0f;
	m_sVertex[0].diffuse = D3DCOLOR_RGBA(0,0,255,0);

	m_sVertex[1].x = 150.0f;
	m_sVertex[1].y = 50.0f;
	m_sVertex[1].z = 1.0f;
	m_sVertex[1].diffuse = D3DCOLOR_RGBA(0,0,255,0);

	m_sVertex[2].x = 150.0f;
	m_sVertex[2].y = 50.0f;
	m_sVertex[2].z = 1.0f;
	m_sVertex[2].diffuse = D3DCOLOR_RGBA(0,0,255,0);

	m_iD3DDevice8->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX), 0,
		D3DFVF_DIFFUSE|D3DFVF_XYZ, D3DPOOL_DEFAULT, &m_iD3DVertBuf8);

	BYTE *ptr;
	m_iD3DVertBuf8->Lock(0, sizeof(m_sVertex), (BYTE**)&ptr, 0);
	memcpy(&ptr,m_sVertex, sizeof(m_sVertex));
	m_iD3DVertBuf8->Unlock();

}

            
But whenever I get to filling out the first structure (sVertex[0]), my program returns to the window desktop. I don´t get any compilation errors and debug reports an access violation error. Is this code "legal"? if not, what should I do to make this work? sHaKaZeD

http://www.shakazed.tk [edited by - shakazed on July 27, 2002 6:26:37 AM] [edited by - shakazed on July 27, 2002 6:28:32 AM] [edited by - shakazed on July 27, 2002 6:29:25 AM] [edited by - shakazed on July 27, 2002 6:30:51 AM] [edited by - shakazed on July 27, 2002 7:53:53 AM]

Share this post


Link to post
Share on other sites
Advertisement
I hope you haven''t copy&pasted the code, cuz you declare sVertex[2] and use m_sVertex.
And you are using a array of 2, so you have sVertex[0] and sVertex[1]...
But else...
Use step by step debugging, but I think it''ll tell you of an access violation...





Those who do not love don''t live.




[MSDN|Google|Bloodshed|My lousy page|email.me]

Share this post


Link to post
Share on other sites

BYTE *ptr;
m_iD3DVertBuf8->Lock(0, sizeof(m_sVertex), (BYTE**)&ptr, 0);
memcpy(&ptr,m_sVertex, sizeof(m_sVertex));
m_iD3DVertBuf8->Unlock();

I think you want memcpy (ptr, ....)
instead of memcpy(&ptr, ....)

What you''re doing now is copying to the address of the pointer, which will write stuff all over your stack. Not sure if thats it but it stood right out to me

Share this post


Link to post
Share on other sites
Apart from the incorrect memcpy, you''re also declaring m_sVertex as being an array of size two, but you''re trying to assign to the third element in m_sVertex[2].


codeka.com - Just click it.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!