Jump to content
  • Advertisement
Sign in to follow this  
Alex Swinney

Vertex Buffer Problem:

This topic is 5402 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 searched for this before I posted, so please, no one get all PO'ed, ok? Anyway..I am attempting to access a vertex buffer and index buffer from a mesh that was initiated by way of a .x file. Everytime I uncomment the code, my app blows up without the window even being displayed. I am wanting to access the vertices and indices in order to separate the triangles from each other. The code that blows up is as follows:
	this->mesh->LockIndexBuffer(D3DLOCK_READONLY,(void **)&indVerts);
	
	this->mesh->LockVertexBuffer(D3DLOCK_READONLY,(void **)&vertices);

	for(unsigned int i = 0,t = 0; i<numFaces;i+=3,t++)
	{
		//i is used to cycle through the index buffer
		//use i like so: vertices[indVerts];
		//this->tris[t].one = vertices[indVerts];
		//this->tris[t].two = vertices[indVerts[i+1]];
		//this->tris[t].three = vertices[indVerts[i+2]];
	}
	this->mesh->UnlockIndexBuffer();
	this->mesh->UnlockVertexBuffer();

Let me know any and all errors you see with this code! Also, here is my vertex structure(along with triangle struct):

struct Vertex2
{
	Vertex2()
	{
		_x = _y = _z = 0;
	}
	Vertex2(float x, float y, float z)
	{
		_x = x;  _y = y;  _z = z;
	}
	float _x, _y, _z,normal[3],xyzb1[3],xyzb5[3],xyzb3[3],xyzw[4];
	float tex,tex3[3], tex5[5], tex7[7];
	static const DWORD FVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_XYZB1 |
							 D3DFVF_XYZB3 | D3DFVF_XYZB5 |D3DFVF_XYZW | 
							 D3DFVF_TEX1 | D3DFVF_TEX3 | D3DFVF_TEX5 | 
							 D3DFVF_TEX7 | D3DFVF_POSITION_MASK | 
							 D3DFVF_TEXCOUNT_MASK;
};


struct Triangle
{
	Triangle()
	{
	}
	Triangle(Vertex2 one, Vertex2 two, Vertex2 three)
	{
		this->one = one;
		this->two = two;
		this->three = three;
	}
	Triangle(Vertex2 one, Vertex2 two, Vertex2 three,D3DXVECTOR3 norm)
	{
		this->one = one;
		this->two = two;
		this->three = three;
		this->normal = norm;
	}

	Vertex2 one, two, three;
	D3DXVECTOR3 normal;
};

Share this post


Link to post
Share on other sites
Advertisement
Have you checked the return values of Lock*Buffer()? And is the tris[] array allocated? What are the values of the indices returned? Can you just read an index into a WORD without the app "blowing up"?

Share this post


Link to post
Share on other sites

1) have you enabled the debug Direct3D runtime and set an appropriate debug output level via the DirectX control panel applet? (see the FAQ for this forum for more).


2) if so, are you getting any Direct3D error output when you run your program in the debugger ?


3) since you're using D3DX, try linking with d3dx9d.lib rather than d3dx9.lib, that will get you extra debug output from D3DX - does it tell you anything ? I suspect it might.


4) when code "blows up", 99.9% of the time the line where the debugger kicked in or a couple of entries down the call stack in the debugger usually reveal exactly what the problem is.

If using MSVC, you can highlight each suspect variable or add a watch to check whether the value is awry. If the value of any of your pointers is: 0, 0xCDCDCDCD, 0xCCCCCCCC, 0xFEFEFEFE or similar number with an obvious "pattern", then it indicates a problem with how you've allocated memory, how you've filled or taken pointers etc.

In particular (as mentioned by Steve) I'd pay particular attention to the values of following variables:

this - memory trashes and failing to allocate
mesh - if the D3DX call failed
tri - failing to allocate or the "wrong" type of allocation

Share this post


Link to post
Share on other sites
Wow, you guys are quick!

Yes, I forgot to mention that I have used the debugger (sorry) and it says:

Unhandled exception at 0x004dbb3f in app.exe: 0xC0000005: Access violation writing location 0xcccccccc.

Yes, it seems that the fix was rather easy, so far. Been beating my head against a desk for nothing it seems..

Ok, I think I have it fixed now, thanks! Might be back, though, need to check my work first ;)


Share this post


Link to post
Share on other sites
"Access violation writing location 0xcccccccc"
MSVC fills uninitialized variables with 0xcccccccc in debug mode. Your tris[] array isn't allocated, so tris has the value 0xcccccccc, which means that accessing tris[0] is dereferencing an invalid pointer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!