Problems with 'resetting' device.

Started by
15 comments, last by cozzie 9 years, 10 months ago

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
Advertisement

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:

That video’s reference count is over 10,000,000!!!!


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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

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

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.

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.

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.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement