Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Directx 11 Draw Causing Memory Leak?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 KieranHay   Members   -  Reputation: 128

Like
0Likes
Like

Posted 03 July 2014 - 12:01 PM

Hi all...

 

I'm having a big problem carrying on with my project because within my Renderer Class there seems to be a memory leak being caused by directx DrawIndexed method. However I'm sure it is obviously something I have done incorrectly. I know there's a leak because I have been looking at task managers process list at the memory and it continually rises, if I comment the line out it doesn't rise. The code is below, there is still a bit of refactoring needed to be done any comments are useful.

DirectX::XMMATRIX camView = camera->GetCamView();
	DirectX::XMMATRIX camProjection = camera->GetCamProjection();
	viewCB_.UpdateSubresource(deviceContext, &camView);
	projCB_.UpdateSubresource(deviceContext, &camProjection);
	viewCB_.BindBuffer(deviceContext, 1, 1, PIPE_LINE_STAGE::VERTEXSHADER);
	projCB_.BindBuffer(deviceContext, 2, 1, PIPE_LINE_STAGE::VERTEXSHADER);
	for (std::list<std::shared_ptr<Object>>::iterator it = _renderQueue.begin(); it != _renderQueue.end(); it++)
	{
		//float clearColor[4] = { 0.0f, 0.0f, 0.25f, 1.0f };

		unsigned int stride = sizeof(Vertex);
		unsigned int offset = 0;
		contentManager->_inputLayoutManager.BindInputLayout(deviceContext, "position");
		PurgeModel& tempModel = *contentManager->_purgeModelManager.GetPurgeModel((*it)->GetModelName());
		tempModel.GetIndexBuffer()->BindBuffer(deviceContext, DXGI_FORMAT_R32_UINT, 0);
		tempModel.GetVertexBuffer()->BindBuffer(deviceContext, 0, 1, stride, offset);

		SetPrimitiveTopology(deviceContext, PRIMITIVE_TOPOLOGY::PRIMITIVE_TOPOLOGY_TRIANGLELIST);
		contentManager->_shaderManager.BindVertexShader(deviceContext, "test"); // shader name will be in world file
		contentManager->_shaderManager.BindPixelShader(deviceContext, "test");
		worldCB_.UpdateSubresource(deviceContext, &(*it)->cube1World);

		worldCB_.BindBuffer(deviceContext, 0, 1, PIPE_LINE_STAGE::VERTEXSHADER);
		int j = tempModel.GetNumIndices();
		deviceContext->DrawIndexed(j, 0, 0); // memory leak is here for some reason
		//deviceContext->GetDeviceContext()->Draw(30, 0); Have tried this too
		
	}
	_renderQueue.clear();	

I do call flush later on and I am using ComPtr, any help will be appreciated as have been lost with this for the past few days.

 

Thanks in advance.

 

 



Sponsor:

#2 Buckeye   GDNet+   -  Reputation: 10693

Like
2Likes
Like

Posted 03 July 2014 - 02:30 PM

Have you done anything else to confirm you do, indeed, have a memory leak? For instance, have you used a debug object (ID3D11Debug) to report live objects before and after rendering?


Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


#3 L. Spiro   Crossbones+   -  Reputation: 21374

Like
2Likes
Like

Posted 03 July 2014 - 02:53 PM

Nothing in your posted code directly increases any reference counts on objects (DrawIndexed() does not leak memory).
You will need to post code that actually modifies object reference counts before anyone can guide you.
What does GetPurgeModel() do?

Side-note: A list is probably the worst way to implement a render queue (it would be faster to just render straight). It should be a plain-ol’-data vector with a matching index array which gets sorted.


L. Spiro


Edited by L. Spiro, 03 July 2014 - 02:55 PM.


#4 ankhd   Members   -  Reputation: 1913

Like
0Likes
Like

Posted 03 July 2014 - 05:15 PM

Hi.
This may or may not help.
But do you lock any vertex buffers. You may be using the wrong vertex format when locking.
I'm asking because I did the some thing some time a go and the app worked for month until I added some new code.
The thing is it never crashed in that part of the code, it turned up in the intersection code in a area totally none related to the error.
So the bug may not be where it breaks in vc or what ever your using. The only way I found the error was to check all code from where it crashed. I even checked my mesh loading class with a fine tooth comb.
So if you are locking any buffers check that all data is valid and if the correct type.

#5 KieranHay   Members   -  Reputation: 128

Like
0Likes
Like

Posted 04 July 2014 - 09:50 AM

I have used the debug layer of directx and here is the output when my application exits:

 I have also tried deleaker and it hasn't found anything.

D3D11 WARNING: Live ID3D11Device at 0x006C611C, Refcount: 3 [ STATE_CREATION WARNING #441: LIVE_DEVICE]
D3D11 WARNING: 	Live ID3D11Context at 0x006C9010, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #2097226: LIVE_CONTEXT]
D3D11 WARNING: 	Live ID3DDeviceContextState at 0x006D3010, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #3145742: LIVE_DEVICECONTEXTSTATE]
D3D11 WARNING: 	Live ID3D11BlendState at 0x006D9124, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #435: LIVE_BLENDSTATE]
D3D11 WARNING: 	Live ID3D11DepthStencilState at 0x006D926C, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #436: LIVE_DEPTHSTENCILSTATE]
D3D11 WARNING: 	Live ID3D11RasterizerState at 0x006D93DC, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #437: LIVE_RASTERIZERSTATE]
D3D11 WARNING: 	Live ID3D11Sampler at 0x006D962C, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #434: LIVE_SAMPLER]
D3D11 WARNING: 	Live ID3D11Query at 0x006D9774, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #438: LIVE_QUERY]
D3D11 WARNING: 	Live IDXGISwapChain at 0x006D98C0, Refcount: 0 [ STATE_CREATION WARNING #442: LIVE_SWAPCHAIN]
D3D11 WARNING: 	Live ID3D11Texture2D at 0x006C185C, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #425: LIVE_TEXTURE2D]
D3D11 WARNING: 	Live ID3D11RenderTargetView at 0x006C260C, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #428: LIVE_RENDERTARGETVIEW]
D3D11 WARNING: 	Live ID3D11Texture2D at 0x006C298C, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #425: LIVE_TEXTURE2D]
D3D11 WARNING: 	Live ID3D11DepthStencilView at 0x006C242C, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #429: LIVE_DEPTHSTENCILVIEW]
D3D11 WARNING: 	Live ID3D11VertexShader at 0x006C327C, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #430: LIVE_VERTEXSHADER]
D3D11 WARNING: 	Live ID3D11InputLayout at 0x006C3044, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #433: LIVE_INPUTLAYOUT]
D3D11 WARNING: 	Live ID3D11PixelShader at 0x006DA8A4, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #432: LIVE_PIXELSHADER]
D3D11 WARNING: 	Live ID3D11Buffer at 0x006F2A64, IntRef: 0 [ STATE_CREATION WARNING #423: LIVE_BUFFER]
D3D11 WARNING: 	Live ID3D11Buffer at 0x006F2CBC, IntRef: 0 [ STATE_CREATION WARNING #423: LIVE_BUFFER]
D3D11 WARNING: 	Live ID3D11Buffer at 0x006F1E54, IntRef: 0 [ STATE_CREATION WARNING #423: LIVE_BUFFER]
D3D11 WARNING: 	Live ID3D11Buffer at 0x006F345C, IntRef: 0 [ STATE_CREATION WARNING #423: LIVE_BUFFER]
D3D11 WARNING: 	Live ID3D11Buffer at 0x006F36B4, IntRef: 0 [ STATE_CREATION WARNING #423: LIVE_BUFFER]
D3D11 WARNING: 	Live ID3D11Texture2D at 0x006F390C, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #425: LIVE_TEXTURE2D]
D3D11 WARNING: Process is terminating. Using simple reporting. Please call ReportLiveObjects() at runtime for standard reporting. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: Live Producer at 0x006C6190, Refcount: 2. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006C9010, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006D3010, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006D9124, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006D926C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006D93DC, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006D962C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006D9774, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006D98C0, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006C185C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006C260C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006C298C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006C242C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006C327C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006C3044, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006DA8A4, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006F2A64, Refcount: -1. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006F2CBC, Refcount: -1. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006F1E54, Refcount: -1. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006F345C, Refcount: -1. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006F36B4, Refcount: -1. [ STATE_CREATION WARNING #0: UNKNOWN]
D3D11 WARNING: 	Live Object at 0x006F390C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN]

so that all looks okay to me. I have ran one before and after rendering and they are the same and as expected. However as I've stepped through this many times the memory usage only goes up sometimes and not every render call.

 

 

Nothing in your posted code directly increases any reference counts on objects (DrawIndexed() does not leak memory).
You will need to post code that actually modifies object reference counts before anyone can guide you.
What does GetPurgeModel() do?

Side-note: A list is probably the worst way to implement a render queue (it would be faster to just render straight). It should be a plain-ol’-data vector with a matching index array which gets sorted.


L. Spiro

 

I completely agree, it doesn't increase reference count and that's why I'm confused about memory going up and not going up when its commented out...

The GetModel method just returns a pointer to a model.

 

I was using a list because I was planning on sorting that but using an index array sounds good.

 

It seems like I am chasing a red herring at the moment and the problem is somewhere else as ankhd said, any ideas?



#6 mhagain   Crossbones+   -  Reputation: 9956

Like
2Likes
Like

Posted 04 July 2014 - 02:28 PM

so that all looks okay to me.

 

This is not OK.  The fact that you still have live objects during shutdown means that you're not managing object lifetimes properly (despite the fact that you state you're using smart pointers) - you have reference counts of 2 so you're not only failing to release some objects properly, but you've also got something or somethings else also holding references to them.  Reference counts of -1 are also weird and suspect.  I'd strongly recommend that you go back through your code and fix all of this mess before even beginning to troubleshoot this observed leak, as a likely source for it is your bad object lifetime management.

 

I'm also quite concerned about this code:

 

deviceContext->DrawIndexed(j, 0, 0); // memory leak is here for some reason
//deviceContext->GetDeviceContext()->Draw(30, 0); Have tried this too

 

D3D11 doesn't have a "GetDeviceContext" method, so that tells me that you're wrapping D3D.  You haven't posted your wrapper code so it's impossible to give you meaningful assistance with any of this.  The only thing I can add is that if fixing up your object lifetimes doesn't resolve this, then the cause of this leak is almost definitely in your wrapper: real D3D draw calls don't leak memory.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#7 Buckeye   GDNet+   -  Reputation: 10693

Like
2Likes
Like

Posted 04 July 2014 - 07:07 PM


you have reference counts of 2 so you're not only failing to release some objects properly

 

I see only the device with a ref count => 2, which shouldn't be a problem. The device, and likely the debug device, hold references at that point.

 

@OP: The negative ref counts look suspicious. Are you releasing objects "manually" which are ComPtrs?? Shouldn't be a particular problem, but more careful management wouldn't hurt.


Edited by Buckeye, 04 July 2014 - 07:21 PM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS