On Thu, Aug 18, 2011 at 8:05 PM, Stefan Dösinger stefandoesinger@gmx.at wrote:
Hi,
I noticed one small issue: On Saturday 13 August 2011 12:22:03 Michael Mc Donnell wrote:
+static HRESULT convert_vertex_buffer(ID3DXMesh *mesh_dst, ID3DXMesh
*mesh_src)
...
- hr = mesh_dst->lpVtbl->LockVertexBuffer(mesh_dst, D3DLOCK_DISCARD,
(void**)&vb_dst); On paper, D3DLOCK_DISCARD is only valid on D3DUSAGE_DYNAMIC buffers. Wine and Windows <= WinVista don't enforce this. Win7 does, and it broke some apps that way.
Ok I see that in dlls/d3d9/tests/buffers.c. So it will fail to lock on Win7 if D3DLOCK_DISCARD is specified and the vertex buffer wasn't created with D3DUSAGE_DYNAMIC?
Am I correct in D3DLOCK_DISCARD makes a copy of the vertex buffer so that the video card can keep reading the old one, and the old vertex buffer memory is released after the video card releases its lock [1]?
In that case it does not make sense to use D3DLOCK_DISCARD at all in CloneMesh, as the video card has not begun to use the new vertex buffer, and it will just add memory overhead. The easiest fix would be to just pass 0 instead of D3DLOCK_DISCARD. I've done that in the updated patch.
I noticed a few more D3DLOCK_DISCARD locks in the mesh.c code.
I guess the other methods should check the mesh options for D3DXMESH_DYNAMIC, D3DXMESH_VB_DYNAMIC, and D3DXMESH_IB_DYNAMIC [2] before using D3DLOCK_DISCARD? I'll write patches for those.
[1] http://msdn.microsoft.com/en-us/library/bb147263(v=vs.85).aspx#Using_Dynamic... [2] http://msdn.microsoft.com/en-us/library/bb205370(v=vs.85).aspx