• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1115
  • Last Modified:

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?
0
johanjohansson
Asked:
johanjohansson
1 Solution
 
kamareyCommented:
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?
0
 
johanjohanssonAuthor Commented:
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.
0
 
fl0ydCommented:
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.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
johanjohanssonAuthor Commented:
Yeah, I release them at the end of the app.
0
 
joachimcCommented:
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
0
 
johanjohanssonAuthor Commented:
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.
0
 
fl0ydCommented:
When optimizing your application for speed you will most certainly have to use more than 1 VertexBuffer. If you put all your static data and dynamic data in the same buffer you will not be able to take advantage of hardware TnL for example. If you look at IDirect3DDevice8::SetStreamSource check the first parameter - it's called StreamNumber. So it is possible to use more than one VertexBuffer at the same time.

On your second question: Like you said, calling Release() is the way to go. You are not responsible for deleting it - it has its own reference counting mechanism and destroys itself automatically when it reaches 0.
0
 
jacobkristensenCommented:
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.
0
 
Jan LouwerensSoftware EngineerCommented:
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
0
 
CleanupPingCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now