Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Creating vertex buffers in DirectX

Posted on 2002-06-24
11
Medium Priority
?
1,102 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

670 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