Sign in to follow this  
Kamil9132

Releasing vertex buffer

Recommended Posts

Kamil9132    135

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
Buckeye    10747


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
L. Spiro    25620

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
Kamil9132    135

@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

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