Jump to content
  • Advertisement
Sign in to follow this  

Problem with DX in Retail Mode...

This topic is 4117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have a GraphicDevice class that wraps a D3D Device. For the initialization I'm using this code:
	D3DPRESENT_PARAMETERS presentParameters;

	ZeroMemory(&presentParameters, sizeof(presentParameters));

	presentParameters.BackBufferWidth				= gameWindow.GetClientWidth();
	presentParameters.BackBufferHeight				= gameWindow.GetClientHeight();
	presentParameters.BackBufferFormat				= D3DFMT_X8R8G8B8;
	presentParameters.BackBufferCount				= 1;
	presentParameters.MultiSampleType				= D3DMULTISAMPLE_NONE;
	presentParameters.MultiSampleQuality			= 0;
	presentParameters.SwapEffect					= D3DSWAPEFFECT_DISCARD;
	presentParameters.Windowed						= true;
	presentParameters.EnableAutoDepthStencil		= true;
	presentParameters.AutoDepthStencilFormat		= D3DFMT_D24S8;
	presentParameters.Flags							= 0;
	presentParameters.FullScreen_RefreshRateInHz	= D3DPRESENT_RATE_DEFAULT;
	presentParameters.PresentationInterval			= D3DPRESENT_INTERVAL_IMMEDIATE;
	presentParameters.hDeviceWindow					= gameWindow.GetWindowHandler();

	IDirect3D9* d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
	assert(d3d9 != NULL);

	D3DCAPS9 caps;
	HRESULT result = d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);

	DWORD vertexProcessing =

	result = d3d9->CreateDevice(

	unsigned long references = d3d9->Release();

	assert(references == 0);
As you can see, I'm asserting that the references when releasing the D3D9 Interface are zero. In d3d debug mode everything is ok while in retail mode the assertion is triggering with a references value == 1!!! Am I missing something? I'm using the D3D SDK of August 2006... Thanks a lot!

Share this post

Link to post
Share on other sites
Original post by Puffarbubbole
Also, is it actually correct to do this kind of assertion?
Relying on the result of AddRef() or Release() is a bad idea, so yes - you're probably wrong.

However, I'm more surprised your code works in debug. Standard COM rules should stop an interface being released before all it's clients have been. Your device is a child of the D3D9 object, thus the D3D9 object shouldn't be released before the device is - regardless of what your application does. This would feed into my original assertion that the value returned is not actually that useful - there is nothing in the COM spec that *required* a specific value or class of value from these calls...


Share this post

Link to post
Share on other sites
My ignorance about COM is really evident here =)

I'm releasing the stuff in the correct order now and it works... Still I don't get why I shouldn't rely on the result of Release... I mean, I added an assertion when releasing the device and it was triggering until I removed all the memory leaks so it seemed to work. There is any other way to do this?

Share this post

Link to post
Share on other sites
The general rule with COM interfaces is to release in the opposite order of creation. The reason being that an interface can create another interface (like D3D creating the device), which increments the reference count. If you release in the wrong order, then one of the releases might not work properly, so you'll have a nonzero reference count, which more than likely gives you a memory leak.

I'm with jollyjeffers, I'm shocked that it even worked in debug.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!