# CreateVertexBuffer() is creating a VB with the same value as one that already exists.

This topic is 4762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have found the cause of a bug I've been getting just trying to render 2 coloured quads. My code basically goes like this:
CreateVertexBuffer1()
Lock, copy data, Unlock

CreateVertexBuffer2()
Lock, copy data, Unlock

DrawVertexBuffer1()
DrawVertexBuffer2()


LPDIRECT3DVERTEXBUFFER9 VB1, VB2;
CreateVertexBuffer(...., &VB1);
CreateVertexBuffer(...., &VB2);


then VB1 != VB2. But if you do this:
ReleaseRenderLayers();
m_VLayersToRender.push_back(RENDERLAYER());
m_VLayersToRender.back().v_PaintingData.push_back(RENDERDATA());
CreateVertexBuffer(..., &(m_VLayersToRender.back().v_PaintingData.back().VB));

m_VLayersToRender.back().v_PaintingData.push_back(RENDERDATA());
CreateVertexBuffer(..., &(m_VLayersToRender.back().v_PaintingData.back().VB));


then m_VLayersToRender.back().v_PaintingData[0].VB == m_VLayersToRender.back().v_PaintingData[1].VB Even though the second element of the v_PaintingData vector, and hence the second VB, doesn't even exist by the time the first one is completely created. Even though both VBs are in different places in memory. For some reason, CreateVertexBuffer() is giving them the same values. Hence the same IDirect3DVertexBuffer9 interface object, hence calling the same Lock() function.. blah blah blah. I still don't know why vectors cause this screwup. DirectX hurrah! The bugged code. >_< [Edited by - Defend on January 3, 2006 8:35:13 AM]

##### Share on other sites
Hi,

I've been looking through the code. Is there no chance that ReleaseRenderLayers(); is releasing the VB you create just before calling it (VB #1)?

Also, are both Create functions succeeding? No debug output?

Hope this helps :).

##### Share on other sites
Yeah I removed the Error checking lines to try and clear up what was already some lengthy code. I had checked the DirectX function returns many times. Also no chance of ReleaseRenderLayers() doing anything seedy, its only about 5 straightforward lines.

I had tried absolutely everything before coming to the conclusion that the vectors were causing some screwup, so when I got to that point, I had no more ideas at all for how to fix it. You did manage to come up with a new suggestion though (checking ReleaseRenderLayers()), just, that wasn't it. Wish it was.

The problem was the old compiler I was using! >_< Wasted days using broken code. Zeux in #Gamedev tried to find the bug with me, and eventually he and others suggested ditching my old VC++ 6.0. Suggested with Gusto. And that was it; VC++EE 2005, the new PSDK, and alot of converting to LPCTSTR later, the test program was compiling again and the bugged code working fine.

Thanks for having a go though. As you can see, you're the only one, so much appreciation there.
(And a big thanks to Zeux for reaching my level of stuckness enough to suggest it was the compiler.)

##### Share on other sites
Ok, I'm stupid, but not in the way I'd like.
The bug is still there, I'm just stupid for forgetting that I had edited my test case to actually run properly before switching compilers and libraries.

So now I'm on VC++EE 2005, with the new PSDK, and the bug is still there. Its irritating to be still dealing with the same bug after more than a week, but I'll write a couple of minimal programs to test the bug as acutely as possible. Until then, any more ideas?

##### Share on other sites
This might be a little difficult to test, but I'm a bit worried you might be releasing your VB before you're expecting it to. I see no other way you'd get a new device with the same memory address, and no error/warning.

I get the feeling that the vector interface's push_back() function is destroying your object, after copying it. If you placed any call to Release() on the VB in the objects' destructor (you're using two-tiered vectors, so in either of the two object types), the memory will get released on the push_back() function, I think (I'm really not sure aobut this, the vector class is a big question-mark to me :)).

As a quick test, I'd recommend one of two things:

1) Comment out ANY call to Release on any vertex bufffer.
2) Try using a vector of pointers, instead of a vector of objects. You'll be able to control when the objects are destroyed, and you're more likely to avoid this bug.

I hope I'm accurate on this, but it's still worth a shot :) Good luck, hope this helps.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 34
• 16
• 11
• 11
• ### Forum Statistics

• Total Topics
634122
• Total Posts
3015646
×