access to the vertex data

Started by
23 comments, last by Evil Steve 14 years, 11 months ago
Quote:Original post by Evil Steve
Quote:Original post by Claudio
While if I want to use the vertex buffer "D3DVB" ?


*** Source Snippet Removed ***

Is correct ?
Yes.


The error is:
Unhandled exception at 0x0040119a: 0xC0000005: Access violation reading location 0x00000000


Where is the problem ?
Advertisement
Quote:Original post by Evil Steve
Quote:Original post by Claudio
While if I want to use the vertex buffer "D3DVB" ?



*** Source Snippet Removed ***

Is correct ?
Yes.

Quote:Original post by Claudio
Appear error about "access violation to..."
Because you're not checking return values. What do the Debug Runtimes say?


If I insert a messaggeBox in any case (D3D_Ok or else), don't appear any messagebox.

Quote:Original post by Evil Steve
Quote:Original post by Claudio
While if I want to use the vertex buffer "D3DVB" ?



*** Source Snippet Removed ***

Is correct ?
Yes.

Quote:Original post by Claudio
Appear error about "access violation to..."
Because you're not checking return values. What do the Debug Runtimes say?


If I insert a messaggeBox in any case (D3D_Ok or else), don't appear any messagebox.

Quote:Original post by Claudio
The error is:
Unhandled exception at 0x0040119a: 0xC0000005: Access violation reading location 0x00000000


Where is the problem ?
At the line that dereferences a null pointer. I can't tell you where that is, but if you check your return values, and use the debug runtimes and your Debugger, you'll be able to find it.

EDIT:
Quote:Original post by Claudio
If I insert a messaggeBox in any case (D3D_Ok or else), don't appear any messagebox.
Then that code isn't being executed.
Quote:Original post by Evil Steve
Quote:Original post by Claudio
The error is:
Unhandled exception at 0x0040119a: 0xC0000005: Access violation reading location 0x00000000


Where is the problem ?
At the line that dereferences a null pointer. I can't tell you where that is, but if you check your return values, and use the debug runtimes and your Debugger, you'll be able to find it.

EDIT:
Quote:Original post by Claudio
If I insert a messaggeBox in any case (D3D_Ok or else), don't appear any messagebox.
Then that code isn't being executed.


The returned value is negative: -858993460
Quote:Original post by Claudio
The returned value is negative: -858993460
That valus is 0xcccccccc, which means an uninitialized variable. You're looking at the value before it's been set.

Again, the debug runtimes will tell you WHY it's failing.
Quote:Original post by Evil Steve
Quote:Original post by Claudio
The returned value is negative: -858993460
That valus is 0xcccccccc, which means an uninitialized variable. You're looking at the value before it's been set.

Again, the debug runtimes will tell you WHY it's failing.


Hi, I suppose this was the problem.

So, I've to associate the vertex buffer to the device with:

hRes = D3DDev->SetStreamSource(0, D3DVB, 0, sizeof(VERTEX3D));

during the rendering phase.

Only this ?

So, for create, get and associate the vertex buffer from D3DMesh, I've to use only the above function ?

Where am I in error ?

Thanks for all.

Quote:Original post by Claudio
So, I've to associate the vertex buffer to the device with:

*** Source Snippet Removed ***
during the rendering phase.

Only this ?
You only need to call SetStreamSource() after creating the vertex buffer, and then you can call DrawPrimitive or DrawIndexedPrimitive, yes.

Quote:Original post by Claudio
So, for create, get and associate the vertex buffer from D3DMesh, I've to use only the above function ?
If you're using meshes, why not use DrawSubset() instead of circumventing everything that ID3DXMesh is trying to do? But yes, that's all you should need to do if you want to get the VB from a mesh and set it as active on a device.

Quote:Original post by Claudio
Where am I in error ?
What is the error?
The VB is created and associated to the D3D device with:

	VERTEX3D Vertices;	hRes = D3DDev->CreateVertexBuffer(sizeof(Vertices), D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &D3DVB, NULL);	if (FAILED(hRes)) return hRes;	hRes = D3DDev->SetStreamSource(0, D3DVB, 0, sizeof(VERTEX3D)); ///////////	if (FAILED(hRes)) return hRes;


and the access to the vertex data is with:

        VERTEX3D * vertex = NULL;	VOID* pVertices;	D3DVB->Lock(0, 0, &pVertices, D3DLOCK_READONLY);        memcpy(pVertices, (VOID*)&vertex, sizeof(vertex));        // get the total number of vertices:	DWORD numVerts = GetD3DMesh()->GetNumVertices();	for (unsigned int ni = 0; ni < numVerts; ni++)	{                // access to the vertex data	}	D3DVB->Unlock();


Is correct ?

The question are:
-where the initial vertex data are loaded from the D3DMesh ? with "CreateVertexBuffer" ?
-are the vertex data contained in "pVertices" at the fine ?!
-how can I access to the filed of the final data ? because I can't access to "pVertices" at the same manner of "vertex"
-if I wan't print the data contained in "vertex", I've to use simple "vertex" ? because the pronted data are not correct.
Quote:Original post by Claudio
-where the initial vertex data are loaded from the D3DMesh ? with "CreateVertexBuffer" ?
In that code, you have two completely unrelated classes - the vertex buffer, D3DVB and the mesh, D3DMesh. The mesh contains a vertex buffer, which is loaded when the mesh is loaded.

Quote:Original post by Claudio
-are the vertex data contained in "pVertices" at the fine ?!
I don't understand this question, sorry. You're not checking if Lock() succeeds though, so if it's failing, pVertices will be a null or invalid pointer and accessing it will crash your application with an access violation.

Quote:Original post by Claudio
-how can I access to the filed of the final data ? because I can't access to "pVertices" at the same manner of "vertex"
-if I wan't print the data contained in "vertex", I've to use simple "vertex" ? because the pronted data are not correct.
Locking a vertex buffer gives you access to the vertices in that buffer. If you lock a buffer with no flags, then it assumes you want read/write access to it. If you lock a buffer with the D3DLOCK_READONLY flag, you can only read from the buffer and writing to it will in the best case crash, and in the worst case lead to undefined behaviour.

If the contents of the vertex buffer are not as you expect, then you should check that:
1. You're creating the vertex buffer successfully
2. You're locking the vertex buffer successfully
3. That the vertices in the buffer are actually written in at some point
4. That the vertices in the buffer are written in no more than once.

This topic is closed to new replies.

Advertisement