Jump to content
  • Advertisement
Sign in to follow this  
Kamil9132

Releasing vertex buffer

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have function in which i create vertex buffers. I use this function about 10-15sec.

	for (size_t TB_01 = 0; TB_01 < ltextur1D + ltextur2D + ltextur3D + lModeli + lModeliV + lModeliP + lModeliPV; TB_01++){

		InV.resize (WorldDX->W[wk][TB_01].size() + WorldDX->W[wt][TB_01].size());

		for (size_t TB_02 = 0; TB_02 < WorldDX->W[wk][TB_01].size(); TB_02++) InV[TB_02									] = WorldDX->W[wk][TB_01][TB_02].M;
		for (size_t TB_02 = 0; TB_02 < WorldDX->W[wt][TB_01].size(); TB_02++) InV[TB_02 + WorldDX->W[wk][TB_01].size()	] = WorldDX->W[wt][TB_01][TB_02].M;

		WorldDX->VertexSize[TB_01] = InV.size();

	//	if (WorldDX->VertexReady[TB_01]) WorldDX->VertexBuff[TB_01]->Release();

		ZeroMemory (&bd,		sizeof(bd));
		ZeroMemory (&InitData,	sizeof(InitData));

		bd.Usage = D3D11_USAGE_DEFAULT;
		bd.ByteWidth = sizeof (INS) * WorldDX->VertexSize[TB_01];
		bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
		bd.CPUAccessFlags = 0;

		InitData.pSysMem = &InV[0];
		d3d11Device->CreateBuffer (&bd, &InitData, &WorldDX->VertexBuff[TB_01]);

		InV.clear();

		WorldDX->VertexReady[TB_01] = 1;

	}

Should i release buffer before i create this buffer again?

I tried release buffer in this way but i got error:

if (WorldDX->VertexReady[TB_01]) WorldDX->VertexBuff[TB_01]->Release();
Edited by Kamil9132

Share this post


Link to post
Share on other sites
Advertisement


but i got error

 

What error?

 

What type of variable is VertexReady and where do you initialize it, and what value do you initialize is to?

Share this post


Link to post
Share on other sites

Should i release buffer before i create this buffer again?

Yes, of course. 1 release for every create. You can’t create it 3 times and release it only once.


I tried release buffer in this way but i got error:

To what was the object initialized? It should be NULL until it is created.
And, more repeating of the above, what error? I assume NULL pointer.

After calling Release(), always set the released pointer to NULL.
	template <typename tnType>
	LSE_INLINE LSVOID LSE_CALL CDirectX11::SafeRelease( tnType &_tObj ) {
		if ( _tObj ) {
			_tObj->Release();
			_tObj = NULL;
		}
	}
It’s not a hack, it’s just safe. It makes Release() work the same way as delete, which also allows you to delete a variable multiple times, provided that after the first time it was then set to NULL.


L. Spiro

Share this post


Link to post
Share on other sites

@Buckeye

VertexReady is array of bools, it is initialize with 0 before creating this buffer.

 

I forgot set this buffer as NULL after Release.

Now it's working.

 

Thanks for help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!