Sign in to follow this  

D3DXLoadSurfaceFromFile failed

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

This topic is 4719 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this