I noticed some strangeness when passing a VERTEX
structure to a buffer. At first I thought it was a faulty custom function for reading into .obj files, but debugging further narrowed the problem. Take for instance:
struct VERTEX{
XMFLOAT3 Translation;
D3DXCOLOR Color;
};
and it's instance:
VERTEX foo[] = {
{XMFLOAT3(-0.5f, 0.0f, 0.0f), D3DXCOLOR(1.0f,1.0f,1.0f,1.0f)},
{XMFLOAT3(-0.5f, 0.5f, 0.0f), D3DXCOLOR(1.0f,1.0f,1.0f,1.0f)},
{XMFLOAT3(0.0f, 0.0f, 0.0f), D3DXCOLOR(1.0f,1.0f,1.0f,1.0f)},
{XMFLOAT3(0.0f, 0.5f, 0.0f), D3DXCOLOR(1.0f,1.0f,1.0f,1.0f)},
{XMFLOAT3(0.9f, 0.0f, 0.0f), D3DXCOLOR(0.0f,1.0f,1.0f,1.0f)},
{XMFLOAT3(2.0f, 0.9f, 0.0f), D3DXCOLOR(0.0f,1.0f,0.0f,1.0f)},
};
Work perfectly when passed into a vertex buffer.
Dynamically creating an array instance of the structure yields strange results. I'll see one vertex show up, or none. Here's an example, imagine foo
as being a function returning a [working] VERTEX*
array of vertices:
VERTEX *bar= new VERTEX[barsize];
VERTEX foo[] = {
{XMFLOAT3(-0.5f, 0.0f, 0.0f), D3DXCOLOR(1.0f,1.0f,1.0f,1.0f)},
{XMFLOAT3(-0.5f, 0.5f, 0.0f), D3DXCOLOR(1.0f,1.0f,1.0f,1.0f)},
{XMFLOAT3(0.0f, 0.0f, 0.0f), D3DXCOLOR(1.0f,1.0f,1.0f,1.0f)},
{XMFLOAT3(0.0f, 0.5f, 0.0f), D3DXCOLOR(1.0f,1.0f,1.0f,1.0f)},
{XMFLOAT3(0.9f, 0.0f, 0.0f), D3DXCOLOR(0.0f,1.0f,1.0f,1.0f)},
{XMFLOAT3(2.0f, 0.9f, 0.0f), D3DXCOLOR(0.0f,1.0f,0.0f,1.0f)},
};
bar=foo;
And later on...
memcpy(MappedResource.pData, &bar, sizeof(bar));
Am I doing something funny trying to access the data that foo
points to, such that only the first set of coordinates get passed in?
*edit: When writing this post, foo and bar got mixed. This post now shows the correct example.