🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

A memory leak is detected on instructions where I don't see anything

Started by
7 comments, last by ddlox 3 years, 6 months ago

Hi,

I need help because my profiler indicates that there are huge leaks on some instructions, and I don't understand why.

Could you help me ?

struct VS_CONSTANT_BUFFER_G_BUFFER
{
	XMFLOAT4X4A viewWorld ;
	XMFLOAT4X4A projViewWorld;
	bool normalMappingEnabled;
	//bool padding[15];
};
{
		VS_CONSTANT_BUFFER_G_BUFFER dataVSconstantBufferGBufferPass;
		HRESULT hr;
		
		//memory leak indicated here
		hr = deferredContext->Map(GbufferVsPassConstants, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);

		// Get a pointer to the data in the constant buffer.
		//auto dataVSconstantBufferGBufferPass = reinterpret_cast <VS_CONSTANT_BUFFER_G_BUFFER *>(mappedResource.pData);
		//memcpy(mappedResource.pData, dataVSconstantBufferGBufferPass, sizeof(dataVSconstantBufferGBufferPass));

		// Copy the matrices into the constant buffer.
		dataVSconstantBufferGBufferPass.viewWorld = viewWorld;
		dataVSconstantBufferGBufferPass.projViewWorld = projViewWorld;
		dataVSconstantBufferGBufferPass.normalMappingEnabled = D3D11Rendering::normalMappingEnabled;

		memcpy(mappedResource.pData, &dataVSconstantBufferGBufferPass, sizeof(dataVSconstantBufferGBufferPass));

		// Unlock the constant buffer.
		deferredContext->Unmap(GbufferVsPassConstants, 0);

		

		//memory leak indicated here too
		deferredContext->VSSetConstantBuffers(0, 1, (ID3D11Buffer* const*)&GbufferVsPassConstants);
		
		GbufferVsPassConstants->Release();
		deferredContext->Flush();
	}
Advertisement

Are you sure that the memcpy line does what you want it to do? That mappedResource.pData is something valid and that sizeof(dataVSconstantBufferGBufferPass) is the size of dataVSconstantBufferGBufferPass in bytes? (I can't see what the types within VS_CONSTANT_BUFFER_G_BUFFER are)

Are you sure that the leak is here, and not anywhere else?

The program does what I need, except for memory leaks.

I am not sure that the leaks are here, it is Intel Inspector which indicated me that.

And what about the memcpy args and the types within VS_CONSTANT_BUFFER_G_BUFFER?

theScore said:
GbufferVsPassConstants

what's this ?

It is a pointer created by "CreateBuffer" from Directx 11.

theScore said:

It is a pointer created by "CreateBuffer" from Directx 11.

And is the pointer something proper or does it point to something that was deallocated, or perhaps it is null?

ok, purely based on the code u showed here, things to check:

  • check that GbufferVsPassConstants is created/destroyed symmetrically (basically that you are not creating N times and destroying N-1 times); in other words, make sure GbufferVsPassConstants is not created N+1 times before it is destroyed and before Map( ) is called
  • make sure mappedResource is created like this:
    D3D11_MAPPED_SUBRESOURCE mappedResource;

If all appears right then:

theScore said:
…it is Intel Inspector which indicated me that.

You may have to show us this (or any other errors) in a screenshot or vid…

until then ?

EDIT: Also check ERROR return values for CreateBuffer( ) , Map ( ) , etc…

This topic is closed to new replies.

Advertisement