Jump to content
  • Advertisement
Sign in to follow this  
LemonLime

D3DXSaveSurfaceToFile... bugged or functional?

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

My app tries to(!) save the render target to a bitmap in the following manner...
	IDirect3DSurface9* pSurface = NULL;

	if (FAILED (pD3DDevice->GetRenderTarget(0, &pSurface)))
	{
		Log("FAILED: GetRenderTarget()");
		return false;
	}

	char szFilename[MAX_PATHNAME];

	GetWindowsDirectory(szFilename, MAX_PATHNAME);
	PathAddBackslash(szFilename);
	strcat(szFilename, "BGEye.bmp");

	if (FAILED (D3DXSaveSurfaceToFile(
		szFilename, // LPCTSTR pDestFile,
		D3DXIFF_BMP, // D3DXIMAGE_FILEFORMAT DestFormat,
		pSurface, // LPDIRECT3DSURFACE9 pSrcSurface,
		NULL, // const PALETTEENTRY *pSrcPalette,
		NULL // const RECT *pSrcRect
		)))
	{
		Log("FAILED: D3DXSaveSurfaceToFile()");
		SAFE_RELEASEX(pSurface);
		return false;
	}

	SAFE_RELEASEX(pSurface);
... but if the render target is greater than a certain size, it fails (I'm not sure exactly where it fails, but it's at a resolution greater than 1024*768). Firstly, is this a bug? and secondly, if there is a bug, where is it likely to be (DirectX or my GFX Card driver)? I'm using the August 2005 libraries.

Share this post


Link to post
Share on other sites
Advertisement
If your render target is created using CreateRenderTarget or something similar, there shouldn't be any problems. If you're doing this to take a screenshot of your application, there's a slightly different way to do that. Take a look at this article: http://www.gamedev.net/reference/articles/article1844.asp It uses DirectX 8.1 but the steps are identical for the current SDK.

neneboricua

Share this post


Link to post
Share on other sites
Thanks...

My code now looks like this (I need the back buffer, not the front buffer)...


IDirect3DSurface9* pSurface;

if (FAILED (pD3DDevice->CreateOffscreenPlainSurface(
setup.dwWidth, // UINT Width,
setup.dwHeight, // UINT Height,
D3DFMT_A8R8G8B8, // D3DFORMAT Format,
D3DPOOL_SCRATCH, // DWORD Pool,
&pSurface, // IDirect3DSurface9** ppSurface,
NULL // HANDLE* pSharedHandle
)))
{
Log("FAILED: GetRenderTarget()");
return false;
}

if (FAILED (pD3DDevice->GetBackBuffer(
0, // UINT iSwapChain,
0, // UINT BackBuffer,
D3DBACKBUFFER_TYPE_MONO, // D3DBACKBUFFER_TYPE Type,
&pSurface // IDirect3DSurface9 **ppBackBuffer
)))
{
//do error handling etc...
Log("FAILED: GetBackBuffer()");
SAFE_RELEASEX(pSurface);
return false;
}

char szFilename[MAX_PATHNAME];

GetWindowsDirectory(szFilename, MAX_PATHNAME);
PathAddBackslash(szFilename);
strcat(szFilename, "BGEye.bmp");

if (FAILED (D3DXSaveSurfaceToFile(
szFilename, // LPCTSTR pDestFile,
D3DXIFF_BMP, // D3DXIMAGE_FILEFORMAT DestFormat,
pSurface, // LPDIRECT3DSURFACE9 pSrcSurface,
NULL, // const PALETTEENTRY *pSrcPalette,
NULL // const RECT *pSrcRect
)))
{
Log("FAILED: D3DXSaveSurfaceToFile()");
SAFE_RELEASEX(pSurface);
return false;
}

SAFE_RELEASEX(pSurface);



... but the same problem occurs; when the resolution is above (~)1280*1024, D3DXSaveSurfaceToFile() fails.

Share this post


Link to post
Share on other sites
According to the help the possible return values for D3DXSaveSurfaceToFile() are...

Quote:

Return Value


If the function succeeds, the return value is D3D_OK.

If the function fails, the return value can be the following.


D3DERR_INVALIDCALL The method call is invalid. For example, a method's parameter may have an invalid value.



... as for what the debug screen says, that would take a bit of work... (I'll try to do that now :) )

Share this post


Link to post
Share on other sites
Quote:
Original post by LemonLime
Quote:
What does the debug runtime say?


Apologies; I either don't know how to answer this question, or it says nothing.

When a DirectX function fails, not only is an error code returned, but a text string is also printed to the debug output stream (aka. debug spew) describing the reason _why_ the function failed. Take a look at the Forum FAQ for details on getting this info. It is indispensible to use the Debug Runtime while developing DirectX applications.

neneboricua

Share this post


Link to post
Share on other sites
Thanks for the links... I got some debug output...


Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shell32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shlwapi.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\d3dx9_27.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\d3d9.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\d3d8thk.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\version.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\winmm.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-
Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\comctl32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\d3d9d.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\d3dx9d_27.dll', no matching symbolic information found.
Direct3D9: (INFO) :======================= Hal MixedVP device selected

Loaded 'C:\WINDOWS\system32\usp10.dll', no matching symbolic information found.
Direct3D9: (ERROR) :Failed to create driver surface
Direct3D9: (ERROR) :Error during initialization of surface. CreateRenderTarget/CreateDepthStencil failed
Direct3D9: (ERROR) :Failure trying to create render-target
D3D9 Helper: IDirect3DDevice9::CreateRenderTarget failed: D3DERR_OUTOFVIDEOMEMORY
The thread 0xF0C has exited with code 1 (0x1).
The program 'F:\Copy of bgeye v1_05\Debug\BGEye.exe' has exited with code 1 (0x1).


... the answer is now obvious, my 32MB GF2 hasn't got enough memory.

How would I test for this fault at runtime (retail build), should I test for undocumented return values?

EDIT: The return value is undocumented...


FAILED: D3DXSaveSurfaceToFile()
D3DXSaveSurfaceToFile() exited with error code -2005532292 (D3DERR_INVALIDCALL = -2005530516)


EDIT2: The returned value is undocumented (but correct)...


FAILED: D3DXSaveSurfaceToFile()
D3DXSaveSurfaceToFile() exited with error code -2005532292 (D3DERR_INVALIDCALL = -2005530516)(D3DERR_OUTOFVIDEOMEMORY = -2005532292)


[Edited by - LemonLime on September 3, 2005 3:34:38 AM]

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!