[?] Writing Vertex and Index data to mesh.

07/20/2012 02:37 sozoku#1
[Only registered and activated users can see links. Click Here To Register...]
Mesh ends up with incorrect/null values. What is wrong/what isnt there?

Really would appreciate some help, getting headaches from filling a ID3DXMesh.


Sozo/Moot.
07/22/2012 16:15 Tyrar#2
invalid vertex format?
07/22/2012 21:44 sozoku#3
Quote:
Originally Posted by HeavyHacker View Post
invalid vertex format?
Im pretty sure the vertex format isn't the problem as I created the mesh with the same FVF as the vertices being copied.

Edit:
It came up like this, so it maybe a pointer thing when using memcpy.
Quote:
Mesh {
32;
12.619567;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
07/23/2012 16:18 tnd0#4
looks like you are trying to copy data from a dynamic array. dynamic arrays are stored as pointers and their data do not necessarily have to be appended to eachother, meaning each element is stored 'somewhere randomly' in memory and your copy function expects all elements to be at "element1 + sizeof(element) * elementindex". use constant arrays instead.
07/23/2012 17:06 sozoku#5
Quote:
Originally Posted by tnd0 View Post
looks like you are trying to copy data from a dynamic array. dynamic arrays are stored as pointers and their data do not necessarily have to be appended to eachother, meaning each element is stored 'somewhere randomly' in memory and your copy function expects all elements to be at "element1 + sizeof(element) * elementindex". use constant arrays instead.
Epvp was down a bit last night so I didn't get to update.

Well I have half solved the problem, quite similar to what you said but then again not much, it was something to do with
[Only registered and activated users can see links. Click Here To Register...]
This works on an off. So what your saying about it needing it to be constant makes most sense. Thanks for that going to try that now.

Edit: Seems like that I'm short of knowledge to pursue what you advise. :U
Edit2: I'm also seeing that I'm taking account the offset to the start of the stream, which I've fixed. And also relating to what you have said, when locking data, do I need to take into account flags to achieve constant void?
Edit3: So far:
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
Now for some reason I'm crashing.
Edit4:
Got it to stop crashing by just adding a & before vb. But as I get the mesh, I can help but feel that the vertices are inverted in some way. Maybe relating to the indices.
[Only registered and activated users can see links. Click Here To Register...] <-- What is supposed to be a ring.
07/23/2012 17:52 tnd0#6
show how you fill the Vertex and Index arrays. and stop using screenshots, there's a [ CODE] tag for that.
07/23/2012 17:58 sozoku#7
Code:
pDevice->GetFVF(&ppFVF);
				D3DXCreateMeshFVF(primCount,NumVertices,0,ppFVF,pDevice,&mesh); //D3DXMESH_SYSTEMMEM
				pDevice->GetStreamSource(0,&ppStreamData,&poffsetinbytes,&pstride);
				pDevice->GetIndices(&ppIndexData);
				
				ppStreamData->GetDesc(&pDescv);
				mesh->LockVertexBuffer( 0, &VertexPtr );
				ppStreamData->Lock(poffsetinbytes,pDescv.Size, (void**)&Vb,0); //ppStreamData->Lock(poffsetinbytes,pDescv.Size, (void**)Vb,0);
				memcpy( VertexPtr, Vb, (size_t)NumVertices * pstride );
				mesh->UnlockVertexBuffer();
				ppStreamData->Unlock();

				ppIndexData->GetDesc(&pDesc);
				UINT size = (pDesc.Format == D3DFMT_INDEX32) ? sizeof( UINT ) : sizeof( USHORT );
				mesh->LockIndexBuffer( 0, &IndexPtr );
				ppIndexData->Lock(0,pDesc.Size, &Ib,0); //ppIndexData->Lock(0,pDesc.Size,(void**)Ib,0);
				memcpy( IndexPtr, Ib, (size_t)NumVertices * size );
				mesh->UnlockIndexBuffer();
				ppIndexData->Unlock();
Technically, I'm getting vertex and index data from the current stream via a DIP hook and filter... :|
07/23/2012 19:14 tnd0#8
I was asking how you fill your 'Vb' and 'Ib' var. post more source, i cant help you with that information.
07/23/2012 19:26 sozoku#9
Quote:
Originally Posted by tnd0 View Post
I was asking how you fill your 'Vb' and 'Ib' var. post more source, i cant help you with that information.
I dont think you understand. Its getting vb and ib from a drawindexedprimitive call.
07/23/2012 19:26 MrSm!th#10
Quote:
Originally Posted by tnd0 View Post
looks like you are trying to copy data from a dynamic array. dynamic arrays are stored as pointers and their data do not necessarily have to be appended to eachother, meaning each element is stored 'somewhere randomly' in memory and your copy function expects all elements to be at "element1 + sizeof(element) * elementindex". use constant arrays instead.
Wat?
07/23/2012 20:04 tnd0#11
Quote:
Originally Posted by MrSm!th View Post
Wat?
Imagine you have 2 arrays, a dynamic and a static one, both arrays of integer.

[Only registered and activated users can see links. Click Here To Register...]

first line: integer(&SomeStaticArray) = 0x00423EDC
second line: integer(&SomeDynamicArray) = 0x00423EEC
third line: integer(&SomeDynamicArray[0]) = 0x0063C2A8

now imagine you want to copy those data to your GPU memory via memcpy. what does memcopy? you pass 2 pointers, your source and your destination and the length. copying the static array with a pointer to the array is fine because the data are all located there. copying the dynamic array by passing a pointer to it, you will only copy the pointer to the first element and then some zero's if you're lucky, or get an AV else.

thats the difference.

Quote:
I dont think you understand. Its getting vb and ib from a drawindexedprimitive call.
you dont want my help, do ya? the code you posted looks fine as far as one can tell, unless your variables are set up wrong, which I cant tell because I dont see how you fill your buffers. drawindexedprimitve does not fill a buffer, it takes a pointer to a dxstruct which gets passed to the gpu. if you hooked it and grabbed that buffer, it looks like you only grabbed the pointer so you gotta read what that pointer points to.
07/23/2012 20:22 sozoku#12
Quote:
Originally Posted by tnd0 View Post
Imagine you have 2 arrays, a dynamic and a static one, both arrays of integer.

[Only registered and activated users can see links. Click Here To Register...]

first line: integer(&SomeStaticArray) = 0x00423EDC
second line: integer(&SomeDynamicArray) = 0x00423EEC
third line: integer(&SomeDynamicArray[0]) = 0x0063C2A8

now imagine you want to copy those data to your GPU memory via memcpy. what does memcopy? you pass 2 pointers, your source and your destination and the length. copying the static array with a pointer to the array is fine because the data are all located there. copying the dynamic array by passing a pointer to it, you will only copy the pointer to the first element and then some zero's if you're lucky, or get an AV else.

thats the difference.



you dont want my help, do ya? the code you posted looks fine as far as one can tell, unless your variables are set up wrong, which I cant tell because I dont see how you fill your buffers. drawindexedprimitve does not fill a buffer, it takes a pointer to a dxstruct which gets passed to the gpu. if you hooked it and grabbed that buffer, it looks like you only grabbed the pointer so you gotta read what that pointer points to.
" it looks like you only grabbed the pointer so you gotta read what that pointer points to." Seems so.

"you dont want my help, do ya?" Who said that? I just said that I haven't got anything relating to it in my code beyond that point.

In terms of variables :
Code:
D3DINDEXBUFFER_DESC *pIDesc;
D3DVERTEXBUFFER_DESC *pVDesc;
D3DMATERIAL9* pMaterials=NULL; 
LPD3DXBUFFER materialBuffer;
DWORD numMaterials;
ID3DXMesh* mesh;
IDirect3DIndexBuffer9* ppIndexData;
IDirect3DVertexBuffer9* ppStreamData;
LPDIRECT3DVERTEXBUFFER9 m_vb;
LPDIRECT3DINDEXBUFFER9 m_ib;
DWORD meshstride;
DWORD numvert;
DWORD numfaces;
LPVOID *ppbData=NULL;
BYTE* pVertices=NULL;
DWORD ppFVF;
UINT poffsetinbytes; 
UINT pstride;
LPVOID VertexPtr;
LPVOID IndexPtr;
const void *Ib;
const void *Vb;
D3DINDEXBUFFER_DESC pDesc;
D3DVERTEXBUFFER_DESC pDescv;
BOOLEAN record = FALSE;
D3DXMATERIAL mat;
IDirect3DTexture9 *g_texture=NULL;
^^ *some of this is irrelevant as it may be copied from other code lazily or not applicable to the problem.
07/24/2012 00:37 MrSm!th#13
What do you mean by "dynamic array"? A linked list?
Because arrays allocated with new or std::vectors are located in a linear order.

edit:

Oh wait, did you mean a double pointer? I mean, a pointer to a pointer or a dynamically allocated two-dimensional array?
Like
Code:
int **ptr = new int*[10];
ptr[0] = new int[10];
Well that would indeed cause problems (even though i wouldn't call that just a "dynamic array", sincen it is actually a two-dimensional array), but I can't imagine how you figured that out of his first code snippet oO
07/24/2012 04:20 sozoku#14
[Only registered and activated users can see links. Click Here To Register...]
Seems like I found a somewhat similar problem on a Russian article comment. This would explain why very simple meshes work fine but others come out patchy as the proper transformation matrices, vertex shaders and so on haven't been applied. If I'm not mistaken.

Now to see if I can get Processvertices() going on in my code...