Link to home
Start Free TrialLog in
Avatar of johanjohansson
johanjohansson

asked on

Creating vertex buffers in DirectX

Hi.

I'm a newbie in terms of DirectX and I am trying to create a simple application which draws bricks (4 vertics each).

I have 2 vertexbuffers, 1 for background and 1 for drawing bricks, now everything works except that i get a memory leak (Direct3D8: (ERROR) :Memory Address: 00bde8ac lAllocID=91 dwSize=0000101f, ReturnAddr=00a0e226 (pid=0000078c)) times 80 when i create the second vertexbuffer. Even if I don't do nothing with it I get this error...

I create the 2 like this:
 if( FAILED( g_pD3DDevice->CreateVertexBuffer(
          3*sizeof(CUSTOMVERTEX),
          0, D3DFVF_CUSTOMVERTEX,
          D3DPOOL_DEFAULT, &g_pVB ) ) )
      return E_FAIL;

if( FAILED( g_pD3DDevice->CreateVertexBuffer(
          4*PLAYSIZE*sizeof(CUSTOMVERTEX),
          0, D3DFVF_CUSTOMVERTEX,
          D3DPOOL_DEFAULT, &g_pVBBricks ) ) )
      return E_FAIL;


Any ideas?
Avatar of kamarey
kamarey

First go to ControlPanel->DirectX->Direct3D and select Debug Version instead of Retail Version. Also set Debug output level to high.

The second thing: what is CUSTOMVERTEX, D3DFVF_CUSTOMVERTEX and PLAYSIZE?
Maybe you should write sizeof(D3DFVF_CUSTOMVERTEX)?

Why did you write Dirext3D8(ERROR) if you say that this is a memory leak? I meen can you run your program or not?
Avatar of johanjohansson

ASKER

The error is a memory leak. You see I could run my app but the error was displayed when terminating. I solved this problem by not using more than 1 vertexbuffer, though I cannot understand why one should be denied from having more than 1 vertexbuffer. I would have liked to have seperate buffers for background, sprite_type_1, ... , sprite_type_n etc etc.
Did you call
    g_pVB->Release();
and
    g_pVBBricks->Release();
in your cleanup-code? If not this could cause a memory leak. Also it is recommended to use a little buffers as possible to leverage maximum performance. I'd recommend using 1 vertex buffer with static data and 1 with dynamic data.
Yeah, I release them at the end of the app.
It seems like you are overwriting some memory since it fails when you end the program. Could it be that playsize is incorrect ?

have you added
delete g_pVB;
delete g_pVBBricks;

/Joachim
I can't use delete on a COM-reference, can I? I use the g_pVB->Release() function to decreased the system-reference count on the COM-object...

I'm thinking that I can only have one vertexbuffer at a time, at any time, and no more. I have yet to see a DX app with more than 1 vertexbuffer. Have you seen one?

Well, despite this problem I have successfully created my first game ever, and I did it with 1 vertexbuffer.
ASKER CERTIFIED SOLUTION
Avatar of fl0yd
fl0yd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Of course you can have more vertex buffers!
(you can pick most any of the DX samples that come with the SDK to see examples of this...)

Is your background just one triangle, since you use "3*sizeof(CUSTOMVERTEX)".

Is PLAYSIZE the number of bricks in your game?

Also, could you please post the code for your CUSTOMVERTEX struct and your FVF definition for D3DFVF_CUSTOMVERTEX.
Avatar of Jan Louwerens
If the second CreateVertexBuffer function fails, you still have allocated the memory for the first vertex buffer, so if the second call fails, you should still call g_pVB->Release() on the first buffer
johanjohansson:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.