D3DXLoadSurfaceFromFile failed

Started by
0 comments, last by circlesoft 19 years, 3 months ago
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);
}
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.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )

This topic is closed to new replies.

Advertisement