• 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
lonewolff

Problems with 'resetting' device.

16 posts in this topic

Hi Guys,

I am having a small issue handling 'lost' devices.

The problem is something to do with the surfaces I am using. If I take out all of my surface code (from the entire program), my device handler works fine.

But, I am using surfaces to render my application.

MSDN states that everything that is created on the device ie, surfaces, textures, etc.. need to be released before 'resetting' the device. So, I am handling this like so;

		HRESULT hr=d3dDevice->TestCooperativeLevel();
		if(hr==D3DERR_DEVICELOST)
		{
			Sleep(10);
			return 0;
		}
		else if(hr==D3DERR_DRIVERINTERNALERROR)
			return 133;
		else if(hr==D3DERR_DEVICENOTRESET)
		{
			if(surfaceApplication)
			{
				surfaceApplication->Release();
				surfaceApplication=NULL;
			}
			if(surfaceWindow)
			{
				surfaceWindow->Release();
				surfaceWindow=NULL;
			}
			if(surfaceBackbuffer)
			{
				surfaceBackbuffer->Release();
				surfaceBackbuffer=NULL;
			}

			if(FAILED(d3dDevice->Reset(&d3dpp)))
				return E_FAIL;
		}
I have no geometry or textures loaded in my application. I am just trying to get the renderer to work properly first.

So, I have released everything (except for the device itself) but the handler still returns E_FAIL (unless I get rid of all surface code throught the app).

Any guidance would be awesome smile.png
0

Share this post


Link to post
Share on other sites
Thanks L. Spiro

Yeah, this is all in a class at the moment.

The following are private and all that need releasing (at the end of the app).
 
	// Device
	IDirect3D9* d3dObject;
	IDirect3DDevice9* d3dDevice;
	D3DPRESENT_PARAMETERS d3dpp;
	bool bVSync;

	// Application surface
	IDirect3DSurface9* surfaceApplication;
	IDirect3DSurface9* surfaceWindow;
	IDirect3DSurface9* surfaceBackbuffer;
	RECT DstRect;
So, as it stands I should only have to release the three surfaces in order to reset the device. And if I remove all references to these surfaces, the device does reset happily.

I'll do some more digging though incase I do have a leak somewhere. Edited by lonewolff
0

Share this post


Link to post
Share on other sites
Thanks again. smile.png

It appears that I do have a memory leak somewhere. Thanks for putting me on the right track smile.png

[edit]
It is related to the surfaces somewhere. Just gotta find it ;) Edited by lonewolff
0

Share this post


Link to post
Share on other sites
Double heck the documentation of all your surface-related functions to see which function calls are incrementing the reference counters. The most common cause is that you call a Get function somewhere and don't realize that it has to be paired with a matching Release -- suddenly you're calling Get every frame and the object's ref-count is over 9000!
1

Share this post


Link to post
Share on other sites

Double heck the documentation of all your surface-related functions to see which function calls are incrementing the reference counters. The most common cause is that you call a Get function somewhere and don't realize that it has to be paired with a matching Release -- suddenly you're calling Get every frame and the object's ref-count is over 9000!


That could be it you know.

If have a constant 501636 byte leak, when I start the application and then immediately close it.

I have no geometry coded yet, so it just leaves only the surfaces.

I am cleaning up in the end with this. But, obviously missing something somewhere.
 
		if(surfaceApplication)
			surfaceApplication->Release();
		if(surfaceWindow)
			surfaceWindow->Release();
		if(surfaceBackbuffer)
			surfaceBackbuffer->Release();
		if(d3dObject)
			d3dObject->Release();
		if(d3dDevice)
			d3dDevice->Release();
[edit]
Yep, definately to do with surfaces. I have remarked out all surface code and no leak. So, atleast I am headed in the right direction. Edited by lonewolff
0

Share this post


Link to post
Share on other sites

the object's ref-count is over 9000!

“lonewolf, what does the PIX say about his reference count?”
It’s over 9,000!!!!


L. Spiro


No, that was an example by Hodgman. It isn't over 9000 at all. ;)
0

Share this post


Link to post
Share on other sites

Also, the Release function returns what the new value of the ref-count is after the call. You can add some assertions in your release-on-lost-device code, checking that those values are zero -- if they're greater than zero, then you've leaked some references somewhere.

2

Share this post


Link to post
Share on other sites

Also, the Release function returns what the new value of the ref-count is after the call. You can add some assertions in your release-on-lost-device code, checking that those values are zero -- if they're greater than zero, then you've leaked some references somewhere.


Nice one! Didn't know that smile.png
0

Share this post


Link to post
Share on other sites

the object's ref-count is over 9000!

“lonewolf, what does the PIX say about his reference count?”
It’s over 9,000!!!!


L. Spiro


No, that was an example by Hodgman. It isn't over 9000 at all. ;)

He was making a reference of his own to this:
http://www.youtube.com/watch?v=SiMHTK15Pik
That video’s reference count is over 10,000,000!!!!


L. Spiro
0

Share this post


Link to post
Share on other sites
Hehe sorry, I didn't get the reference smile.png

[edit]
After some work I traced it down to this and ammended as per the comment

		//This is called every frame	

		if(!FAILED(d3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&surfaceBackbuffer)))
		{
			DstRect.left=0;
			DstRect.top=0;
			DstRect.right=nWindowWidth;		
			DstRect.bottom=nWindowHeight;
			
			if(FAILED(d3dDevice->StretchRect(surfaceApplication,NULL,surfaceBackbuffer,&DstRect,D3DTEXF_LINEAR )))
				return 141;
			
			// ADDED THIS TO THE CODE
			if(surfaceBackbuffer)
			{
				surfaceBackbuffer->Release();
				surfaceBackbuffer=NULL;
			}
		}
If anything still looks nasty here, please let me know smile.png Edited by lonewolff
0

Share this post


Link to post
Share on other sites

Does StretchRect ever fail? If so, you're not releasing the surface reference.


True, I'll modify that.

Although if it does fail it is the end of the road for the application. So at this stage it never does seem to fail. But still worth cleaning up that part of code though smile.png

[edit]
Actually that gets released straight after the return call as it gets handled by the destructor immediately after. Edited by lonewolff
0

Share this post


Link to post
Share on other sites

 

the object's ref-count is over 9000!

“lonewolf, what does the PIX say about his reference count?”
It’s over 9,000!!!!


L. Spiro

 

I would rate this up just on comedic value, but I think that trivializes the ratings system.

0

Share this post


Link to post
Share on other sites
Don't know if it helps, but you can also use a smart pointer for these d3d variables. I use ccomptr (atlbase.h), that way you dont have to keep track of reference counting and releasing. The only thing I do in my constructor and destructor is set them to NULL. If you do so, make sure you have everything set up right when you 'reuse' an object and try to create something again, without releasing the current data.
0

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