• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
KieranHay

Directx 11 Draw Causing Memory Leak?

6 posts in this topic

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.

 

 

0

Share this post


Link to post
Share on other sites

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?

2

Share this post


Link to post
Share on other sites

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
2

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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.

2

Share this post


Link to post
Share on other sites

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
2

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  
Followers 0