Jump to content
  • Advertisement
Sign in to follow this  
giantmung

D3DXCreateSprite (DX9.0c) Failure :( Some input please!

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

Well, I've got some code, trying to create a sprite for some 2d animation, butthe call always fails with an E_OUTOFMEMORY error. I've created a device and a vertex buffer successfully,but cannot create a sprite? I am a bit stumped, as I've gone through and looked at examples and, I just can't find it. <CODE> HRESULT CGraphicMud::initialize( ) { Vertex quadVertices[] = { { 150.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color { 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, }, { 50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, }, }; if( ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) == NULL ) //initialize our device { MessageBox( 0, "Error Initializing DirectX Device!", "Error!", MB_OK ); return E_FAIL; } D3DCAPS9 d3dCaps; pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps ); //specify adapter and get capabilities D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice ); if( FAILED( pd3dDevice->CreateVertexBuffer( 3 * sizeof(Vertex), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &pVertexBuffer, NULL ) ) ) { return E_FAIL; } void *pVertices = NULL; pVertexBuffer->Lock( 0, sizeof(quadVertices), (void**)&pVertices, 0 ); memcpy( pVertices, quadVertices, sizeof(quadVertices) ); pVertexBuffer->Unlock(); D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ), 640.0f / 480.0f, 0.1f, 100.0f ); pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); //create our sprite if( ( D3DXCreateSprite( pd3dDevice, &pSprite ) ) == D3DERR_INVALIDCALL || E_OUTOFMEMORY ) { MessageBox( 0, "Error Creating Sprite!", "Error!", MB_OK ); shutdown(); return E_FAIL; } loadTexture( ); return S_OK; } </CODE> Here's my initialization code above. Variables are defined as: LPDIRECT3D9 pD3D; LPDIRECT3DDEVICE9 pd3dDevice; LPDIRECT3DVERTEXBUFFER9 pVertexBuffer; LPDIRECT3DTEXTURE9 pTexture; LPD3DXSPRITE pSprite; it just doesn't seem to want to work?!

Share this post


Link to post
Share on other sites
Advertisement
I think your problem lies in this line

if( ( D3DXCreateSprite( pd3dDevice, &pSprite ) ) == D3DERR_INVALIDCALL || E_OUTOFMEMORY )

u might put

HRESULT hr = D3DXCreateSprite( pd3dDevice, &pSprite );
if (FAILED(hr))
{
.........
}

Share this post


Link to post
Share on other sites
You can't write an if statement like that. The || (or) operator doesn't work that way.
if( ( D3DXCreateSprite( pd3dDevice, &pSprite ) ) == D3DERR_INVALIDCALL || E_OUTOFMEMORY )

In the above if statement the program evaluates two things. First it checks whether the D3DXCreateSprite() returns D3DERR_INVALIDCALL, and then it checks whether E_OUTOFMEMORY by itself is true, which it will be if it is any positive number. If any one of those conditions is true the if statement will succeed.
You have to write the if statement like this
HRESULT hr = D3DXCreateSprite( pd3dDevice, &pSprite );
if (hr == D3DERR_INVALIDCALL || hr == E_OUTOFMEMORY)
{
// Do things
}

or as yuhaobo wrote above
HRESULT hr = D3DXCreateSprite( pd3dDevice, &pSprite );
if (FAILED(hr))
{
// Do things
}

otherwise the if statement is bound to always be true.

Regards

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!