Sign in to follow this  
Joseph1290

Problems with CreateVertexBuffer (DX 9)

Recommended Posts

Joseph1290    122
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;

Share this post


Link to post
Share on other sites
dave    2187
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.

Share this post


Link to post
Share on other sites
Joseph1290    122
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=00000744
Direct3D9: (INFO) :MemFini!
Direct3D9: (WARN) :Memory still allocated! Alloc count = 68606
Direct3D9: (WARN) :Current Process (pid) = 00000f74


It doesn't appear to indicate something going wrong, but I may be wrong could someone please explain.

Share this post


Link to post
Share on other sites
Joseph1290    122
Now it is outputting this:

Direct3D9: (INFO) :HalDevice Driver style 9

Direct3D9: :DoneExclusiveMode
Direct3D9: (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.

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by Joseph1290
Direct3D9: (ERROR) :Current vertex shader declaration doesn't match VB's FVF[/code]
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?

Share this post


Link to post
Share on other sites
Evil Steve    2017
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)?

Share this post


Link to post
Share on other sites
Joseph1290    122
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this