Hi all,
I started learning directx9 yesterday. I made a function to load bmp files to surfaces:
IDirect3DSurface9* getSurfaceFromBitmap(string filename)
{
HRESULT hResult;
IDirect3DSurface9* surface = NULL;
D3DXIMAGE_INFO imageInfo;
hResult = D3DXGetImageInfoFromFile(filename.c_str(), &imageInfo);
if(FAILED(hResult))
return NULL;
hResult = pd3dDevice->CreateOffscreenPlainSurface(imageInfo.Width, imageInfo.Height, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
if(FAILED(hResult))
return NULL;
hResult = D3DXLoadSurfaceFromFile(surface, NULL, NULL, filename.c_str(), NULL, D3DX_DEFAULT, 0, NULL);
if(FAILED(hResult))
return NULL;
return surface;
}
In my InitDirect3d() function:
bool InitDirect3d()
{
pD3D=NULL;
pd3dDevice=NULL;
if( NULL == (pD3D=Direct3DCreate9(D3D_SDK_VERSION)))
{
return false;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = 640;
d3dpp.BackBufferHeight = 480;
d3dpp.hDeviceWindow = hWndMain;
if( FALSE( pD3D->CreateDevice( D3DADAPTER_DEFAULT,
D3DDEVTYPE_REF,
hWndMain,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&pd3dDevice) ) )
{
return false;
}
surf = getSurfaceFromBitmap("star.bmp");
if(surf==NULL)
return false;
return true;
}
When i compile program, there isn't any problems. But program just crashes without an error.
I tried to comment other lines in getSurfaceFromBitmap function, it only crashes while hResult = pd3dDevice->CreateOffscreenPlainSurface(imageInfo.Width, imageInfo.Height, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL); line uncommented.
Any suggestions?