Skip to main content
GameDev.net gamedev.net
🔒 Locked

Whats wrong with my code?

Started by SikCiv Nov 20, 2000 at 7:47 PM 1 replies 200+ views
Original Post
SikCiv
SikCiv
Im trying to implement a DX8 Sprite3D system in my app, but why does my app crash when it gets to the ->draw function?

// Sprite creation function:
bool CreateSprite()
{
    HRESULT        hr;

  
     // Create the 3D sprite.
    hr = D3DXCreateSprite(lpD3DDevice, &lpD3DXSprite);
    if(FAILED(hr))
    {
        return FALSE;
    }


    lpDDSSrc = DDLoadBitmap3D( "sprite1.bmp");

    if(lpDDSSrc == NULL)
    {
        return FALSE
    }

    return TRUE;
}






LPDIRECT3DTEXTURE8 DDLoadBitmap3D( char *szBitmap )
{
    LPDIRECT3DTEXTURE8 lpDDSTemp;
    HRESULT hr;

    hr = D3DXCreateTextureFromFile( lpD3DDevice, szBitmap,
                                           &lpDDSTemp );


// The below code doesnt work in DX8 anymore.
//    hr = D3DXCreateTextureFromFile(
//            lpD3DDevice,
//            NULL,                   // dwFlags
//            NULL,                   // auto-width
//            NULL,                   // auto-height
//            NULL,                   // auto-surface type
//            NULL,                   // pointer to Palette
//            &lpDDSTemp,             // pointer 
//           NULL,                    // mip-maps
//            szBitmap,               // file name for texture
//            D3DX_FT_DEFAULT);       // default scaling

    if(FAILED(hr)) 
    {
        return NULL;
    }



    return lpDDSTemp;
}







HRESULT Blit()
{

    HRESULT hr = lpD3DDevice->BeginScene();
    RECT rcSrc = SetRect(0,0,64,64);

    if( FAILED( hr ) )
    {
        return hr;
    }

    // Clear the display
    lpD3DDevice->Clear( 0L, NULL,
                        D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 
                        0L, 1.0f, 0L );

    // CRASHES HERE...
    hr = lpD3DXSprite->Draw(lpDDSSrc ,
                            rcSrc,
                            NULL,
                            NULL,
                            0.0f,
                            NULL,
                            0x00000000);
    
    // End the scene.
    lpD3DDevice->EndScene();



    // Display the backbuffer.
    lpD3DDevice->Present( 0, 0, 0, 0 );

    return hr;
}

 
  Downloads:  ZeroOne Realm
ajhin
ajhin
SikCiv --

I actually haven''t worked much with 2d stuff, but if i recall correctly, lpD3DXSprite is a pointer to a D3D util object (or something like that.)

Anyway, while the D3Dutil objects are not documented, you should be able to debug them. Run your debugger, set a break point at the "draw" function, then step into the function. Hopefully, you will see source code jump up, instead of seeing assembly. Step forward until you hit the line that crashes. . . this should indicate to you which of the arguments to draw is causing the problem. My outrageous guess is that either lpD3DXSprite is not initialized correctly or lpDDsrc is not correct.

Good luck.

quote:
Original post by SikCiv

Im trying to implement a DX8 Sprite3D system in my app, but
why does my app crash when it gets to the ->draw function?





// Sprite creation function:
bool CreateSprite()
{
HRESULT hr;


// Create the 3D sprite.
hr = D3DXCreateSprite(lpD3DDevice, &lpD3DXSprite);
if(FAILED(hr))
{
return FALSE;
}


lpDDSSrc = DDLoadBitmap3D( "sprite1.bmp");

if(lpDDSSrc == NULL)
{
return FALSE
}

return TRUE;
}






LPDIRECT3DTEXTURE8 DDLoadBitmap3D( char *szBitmap )
{
LPDIRECT3DTEXTURE8 lpDDSTemp;
HRESULT hr;

hr = D3DXCreateTextureFromFile( lpD3DDevice, szBitmap,
&lpDDSTemp );


// The below code doesnt work in DX8 anymore.
// hr = D3DXCreateTextureFromFile(
// lpD3DDevice,
// NULL, // dwFlags
// NULL, // auto-width
// NULL, // auto-height
// NULL, // auto-surface type
// NULL, // pointer to Palette
// &lpDDSTemp, // pointer
// NULL, // mip-maps
// szBitmap, // file name for texture
// D3DX_FT_DEFAULT); // default scaling

if(FAILED(hr))
{
return NULL;
}



return lpDDSTemp;
}


HRESULT Blit()
{

HRESULT hr = lpD3DDevice->BeginScene();
RECT rcSrc = SetRect(0,0,64,64);

if( FAILED( hr ) )
{
return hr;
}

// Clear the display
lpD3DDevice->Clear( 0L, NULL,
D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
0L, 1.0f, 0L );

// CRASHES HERE...
hr = lpD3DXSprite->Draw(lpDDSSrc ,
rcSrc,
NULL,
NULL,
0.0f,
NULL,
0x00000000);

// End the scene.
lpD3DDevice->EndScene();



// Display the backbuffer.
lpD3DDevice->Present( 0, 0, 0, 0 );

return hr;
}




SikCiv
SikCiv
D3DUtil uses a different approach, it doesnt actually use D3DXCreateSprite but uses a more complicated technique. Im not 3D litterate (yet) and I just want to get 3D sprites on the screen for now using D3DX. Surely someone else has done it? If so I would like to grab the code if possible. Thanks.
  Downloads:  ZeroOne Realm

Topic Locked

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

Sign in to reply to this topic.