Solved

Creating vertex buffers in DirectX

Posted on 2002-06-24
11
1,088 Views
Last Modified: 2007-12-19
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
Comment
Question by:johanjohansson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 2

Expert Comment

by:kamarey
ID: 7111711
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
 
LVL 1

Author Comment

by:johanjohansson
ID: 7112847
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
 
LVL 8

Expert Comment

by:fl0yd
ID: 7125895
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:johanjohansson
ID: 7126129
Yeah, I release them at the end of the app.
0
 
LVL 4

Expert Comment

by:joachimc
ID: 7126591
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
 
LVL 1

Author Comment

by:johanjohansson
ID: 7126635
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
 
LVL 8

Accepted Solution

by:
fl0yd earned 50 total points
ID: 7127301
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
 
LVL 1

Expert Comment

by:jacobkristensen
ID: 7216504
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
 
LVL 5

Expert Comment

by:Jan Louwerens
ID: 7300396
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
 

Expert Comment

by:CleanupPing
ID: 9464364
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question