Sign in to follow this  

Releasing vertex buffer

This topic is 1201 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

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

This topic is 1201 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this