Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ataru

memory leak in DX?

This topic is 5440 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

I have run into some sort of strange memory problem. I am capturing a bunch of still images, after 280 captures I get an E_OUTOFMEMORY error in CreateOffscreenPlainSurface. (This is recording a movie, so not much is done in between. My code is:
HRESULT hr;
	LPDIRECT3DSURFACE9 buffer = NULL; //The front buffer used to get the screenshot


	// Create a surface for the screenshot to be rendered to

	if( FAILED( hr = g_pDevice->CreateOffscreenPlainSurface( screenSizeX, screenSizeY,
								D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &buffer, NULL ) ) )
	{
		gLOG("OFF SCREEN SURFACE FAILED %x\n",hr);
		return hr;
	}



	// Write the front buffer to the surface 

	if (!fullScreen)
	{
		if (FAILED (hr = g_pDevice->GetRenderTarget( 0, &buffer )))
		{
			gLOG("ERROR FRONT BUFFER AQUASITION FAILED %x\n",hr);
			//do error handling etc...

			buffer->Release();
			return hr;
		}
	}
	else
	{
		if( FAILED( hr = g_pDevice->GetFrontBufferData( 0, buffer ) ) )
		{
			gLOG("ERROR FRONT BUFFER AQUASITION FAILED %x\n",hr);
			//do error handling etc...

			buffer->Release();
			return hr;
		}
	}
	
	
	if ( FAILED (hr = D3DXSaveSurfaceToFile( fileName, format, buffer, NULL, NULL ) ) )
	{
			gLOG("ERROR SAVE SURFACE TO FILE FAILED %x\n",hr);
			//do error handling etc...

			buffer->Release();
			return hr;
	}

	// Cleanup

	buffer->Release();
	

	return D3D_OK;
Now maybe I am missing something here, but it looks like every time I run this everything should be released. Is there some sort of memory leak in the DX code itself? Or am I doing something wrong? I know how to fix it, I will only create the surface once, but it seems like this is a bug in the DX code.

Share this post


Link to post
Share on other sites
Advertisement
You create a surface, and store it in ''buffer'', then if not fullscreen, get the frontbuffer pointer and store it in ''buffer''. You have just lost your new surface.

Windowed is fine as it writes into the supplied buffer.

Fullscreen never needed the buffer you made, AND you throw it away.

Share this post


Link to post
Share on other sites
You are right, but actually the error I get is in windowed mode. I would suspect I would get the error even sooner in fullscreen mode.

Share this post


Link to post
Share on other sites

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