Solved

Creating vertex buffers in DirectX

Posted on 2002-06-24
11
1,069 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
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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
DirectXFramework 5 102
Is an Indie RTS practical? 7 113
valarray submatrix representation using gslice 2 104
JAXB showroom collection 2 91
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now