Problems with CreateVertexBuffer (DX 9)

Started by
8 comments, last by Joseph1290 15 years, 8 months ago
Hi, for some reason, when I try to execute CreateVertexBuffer it fails. I have checked on the MSDN site to see if my parameter were wrong but they are not. I cannot figure out what I am doing wrong and its probably right under my nose. Here is my code:

	HRESULT Result = NULL;

	Result = pD3dDevice->CreateVertexBuffer(3*sizeof(VERTEX), 0, D3DFVF_XYZRHW|D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &g_pVB, NULL);

	if(FAILED(Result))
		return NULL;
Advertisement
If you turn on D3D debugging you will get extended debugging information. Go to the control panel which is in the start menu for the DirectX SDK. Slide the slider to the right and check everything. Then you can look in the output debug window in Visual Studio.
Thankyou for the quick reply. OK, so in the debug output it wrote this:

Direct3D9: (WARN) :Vertexbuffer created with POOL_DEFAULT but WRITEONLY not set. Performance penalty could be severe.Direct3D9: :====> ENTER: DLLMAIN(00d8e6e0): Process Detach 00000f74, tid=00000744Direct3D9: (INFO) :MemFini!Direct3D9: (WARN) :Memory still allocated!  Alloc count = 68606Direct3D9: (WARN) :Current Process (pid) = 00000f74


It doesn't appear to indicate something going wrong, but I may be wrong could someone please explain.
That's not related to the code you have there. If CreateVertexBuffer() is failing, the debug runtimes will always print out an error message.
Now it is outputting this:
Direct3D9: (INFO) :HalDevice Driver style 9Direct3D9: :DoneExclusiveModeDirect3D9: (WARN) :Vertexbuffer created with POOL_DEFAULT but WRITEONLY not set. Performance penalty could be severe.Direct3D9: (ERROR) :Current vertex shader declaration doesn't match VB's FVF


Nevermind I managed to fix it.
Quote:Original post by Joseph1290
Direct3D9: (ERROR) :Current vertex shader declaration doesn't match VB's FVF
There you go. Your vertex declaration doesn't say you have D3DFVF_XYZRHW and D3DFVF_DIFFUSE in your vertex structure.

However, that's still not related to that line of code. How are you determining that CreateVertexBuffer is failing? If it's failing, then D3D is outputting an error to the debug output. What if you put a breakpoint on that line and step over it?
Set your second parameter to D3DUSAGE_WRITEONLY.
Its OK I managed to fix my problem.
Quote:Original post by 3ddreams
Set your second parameter to D3DUSAGE_WRITEONLY.
That'll just get rid of the warning, which isn't related to CreateVertexBuffer failing.

Quote:Original post by Joseph1290
Its OK I managed to fix my problem.
How did you manage to fix it (In case someone else with the same problem comes along and finds this thread)?
When I called:
pD3dDevice->SetFVF();


I called it with different settings than when I called CreateVertexBuffer.

i.e. When I called CreateVertexBuffer I used D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1 but when I called SetFVF I used only D3DFVF_XYZRHW | D3DFVF_DIFFUSE. Therefore I just changed D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1 into D3DFVF_XYZRHW | D3DFVF_DIFFUSE.

This topic is closed to new replies.

Advertisement