Skip to main content
gamedev.net
🔒 Locked

Sprite error...

Started by BloodLust666 Apr 6, 2005 at 1:04 PM 8 replies 900+ views
Original Post
BloodLust666
BloodLust666
something's wrong when i try to initialize a sprite interface... Init(cGraphics *Graphics) { if (!(D3DXCreateSprite(m_pGraphics->GetDeviceCOM(), &m_pSprite))) { MessageBox(0,"Error in cSprite::Init()",0,0); return false; } return true; } i keep getting that message box that says there's an error
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
circlesoft
circlesoft
(1) D3DXCreateSprite() returns a HRESULT. Therefore, you need to use the FAILED() or SUCCEEDED() conditional macros with it, instead of a simple bang test. This is because failure codes can be negative, and not just zero.

For example, D3DXCreateSprite() can return two different error codes, D3DERR_INVALIDCALL and E_OUTOFMEMORY. If you only test for 0, an error could sneak through.

Your error test should look like this:

if( FAILED(D3DXCreateSprite( m_pGraphics->GetDeviceCOM(), &m_pSprite))){  MessageBox(0,"Error in cSprite::Init()",0,0);  return false;}

(2) Check your debug output. This will give you detailed information, pertaining to why the call failed. Read DX Debugging in the FAQ.
Nightcrawler99
Nightcrawler99
Ok.. well first off.. why don't you check the return value of the function? That will give you a better indication of why the call fails. Second, if you read the docmentation, you'll see the first parameter you should be passing should be an IDirect3DDevice9 interface pointer. It should look something like this:

IDirect3DDevice9* d3ddev;
ID3DXSprite* sprite;

D3DXCreateSprite(d3ddev,&sprite);

matthughson
matthughson
Not positive about the S_OK define that this function returns on success, but you should also keep in mind that most d3d methods return 0 on success!

Matt Hughson
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
BloodLust666
BloodLust666
ok, i have that fixed now but now when i try to use the ID3DXSprite::Draw() function, it fails...

if(!(m_pSprite->GetSpriteCOM()->Draw(m_pTexture,
&Rect, &D3DXVECTOR2(m_xScale, m_yScale), 0, 0.0f,
&D3DXVECTOR2((float)m_ScreenX, (float)m_ScreenY), 0xFFFFFFFF)))
MessageBox(0,"4",0,0);
return false;
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
BloodLust666
BloodLust666
i don't know if that's even right because when i look up the functino in the documentation, it has different parameters then when i put the ( and it fills in the other params for me...
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Evil Steve
Evil Steve
Quote:
Original post by EvilKnuckles666
ok, i have that fixed now but now when i try to use the ID3DXSprite::Draw() function, it fails...

if(!(m_pSprite->GetSpriteCOM()->Draw(m_pTexture,
&Rect, &D3DXVECTOR2(m_xScale, m_yScale), 0, 0.0f,
&D3DXVECTOR2((float)m_ScreenX, (float)m_ScreenY), 0xFFFFFFFF)))
MessageBox(0,"4",0,0);
return false;

*scream* [smile]
The function returns 0 on success
Most functions return an HRESULT, and as circlesoft said, you should use SUCCEEDED(blah) or FAILED(blah) (where "blah" is your call, for example D3DXCreateSprite(m_pGraphics->GetDeviceCOM(),&m_pSprite))
Evil Steve
Evil Steve
Quote:
Original post by EvilKnuckles666
i don't know if that's even right because when i look up the functino in the documentation, it has different parameters then when i put the ( and it fills in the other params for me...
What version of the SDK are you using? The DX9 October SDK has different parameters for ID3DXSprite::Draw() than the previous version of the DX9 SDK and the DX8 SDK.
BloodLust666
BloodLust666
CRAP!! sry lol i have that for alotta functions and i just didn't change them... i don't remember what version i have but i'm going to download all the updates now
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Cambo_frog
Cambo_frog
Quote:
Original post by EvilKnuckles666
CRAP!! sry lol i have that for alotta functions and i just didn't change them... i don't remember what version i have but i'm going to download all the updates now


Stick with it Evil and good luck!

HTH,
Cambo_frog
For the love of god, please tell me that you've just omitted your error checking code for brevity, and you don't really assume that all those functions succeed.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.