Question

I have the following code:

DirectX::device->CreateVertexBuffer(sizeof(VERTEX) * vertexCount, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, VERTEXFORMAT, D3DPOOL_MANAGED, &vertexBuffer, NULL);

VOID* vertexLocking;
vertexBuffer->Lock(0, 0, (void**)&vertexLocking, 0);
memcpy(vertexLocking, vertices, sizeof(VERTEX) * vertexCount);
vertexBuffer->Unlock();

The problem is that the program keeps breaking on the Lock() function for the vertex Buffer. The error i'm getting is "access violation". But the thing is this worked fine if I put 0 in for the flag.

And because I wanted the buffer's vertices position to change, I tried to change it to D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY and now it stopped working. Why is this?

Était-ce utile?

La solution

I found out what the problem is: Because I'm using D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, it does notwork with D3DPOOL_MANAGED. I switched it to D3DPOOL_DEFAULT and it worked.

Autres conseils

D3DUSAGE_DYNAMIC and D3DUSAGE_WRITEONLY are conflicting. They indicate where to place the Vertex buffer in memory. Most likely when you lock and try to access the memory, it has no idea where to access.

I usually use DYNAMIC for buffers that I'm going to modify on a frequent basis. Go with that flag only and see if that helps you along a little.

MSDN link for usage flag descriptions

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top