Jump to content
  • Advertisement
Sign in to follow this  
miica

D3DXLoadSurfaceFromFile failed

This topic is 5025 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 am learning Direct X 9. In the code below, I test for the D3DXLoadSurfaceFromFile() and noticed that it failed and exit, I don't know what's wrong with my code, can anyone check it for me?
void Render()
{
	IDirect3DSurface9 * backbuffer = NULL;
	IDirect3DSurface9 * ballSurface;

	if(g_pD3DDevice == NULL)
	{
		return;
	}

	g_pD3DDevice->CreateOffscreenPlainSurface(40,40,D3DFMT_X8R8G8B8,
D3DPOOL_DEFAULT,&ballSurface,NULL);

	if(D3DXLoadSurfaceFromFile(ballSurface,NULL,NULL,"ball.bmp",NULL,
D3DX_DEFAULT,0,NULL) == D3DERR_INVALIDCALL)
	{
		exit(1);
	}

    g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    g_pD3DDevice->BeginScene();
	g_pD3DDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&backbuffer);
	g_pD3DDevice->StretchRect(ballSurface,NULL,backbuffer,NULL,D3DTEXF_NONE);
    g_pD3DDevice->EndScene();
    g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}

Share this post


Link to post
Share on other sites
Advertisement
If you enable Direct3D debugging, the debug runtime will spit out a bunch of information when you step over the D3DXLoadSurfaceFromFile() call in your debugger. It will tell you exactly why it failed. Check out this useful page for info on how to do this.

Also, you can't just check for D3DERR_INVALIDCALL, because other failure codes could be returned (and you application would continue on like it was normal). Use the FAILED() macro instead, like this:


if( FAILED( D3DXLoadSurfaceFromFile(ballSurface,NULL,NULL,"ball.bmp",NULL,D3DX_DEFAULT,0,NULL) ) )
{
exit(1);
}

This way, all negative return codes are accounted for. Use the SUCCEEDED() macro in the same manner if you want to see if the call succeeded.

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!