Archived

This topic is now archived and is closed to further replies.

ID3DXSprite Question

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

I''m creating this 2d game using ID3DXSprite. I''m having a massive memory leak somewhere and i believe it''s how i''m doing my rendering. here''s what i do when i move a piece across the board. Each time i move the piece render gets called
  
void Render()
{
     if( dx8._pd3dDevice == NULL)
          return;

     dx8._pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, 
          D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );

     dx8._pd3dDevice->BeginScene();

     DrawScene();

     blocks.showpiece();

     dx8._pd3dDevice->EndScene();

     dx8._pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
void DrawScene()
{
	LPDIRECT3DTEXTURE8 texture;

        //this is my background

	texture = LoadTexture("single.bmp");
	BltSpriteEx( NULL, texture, NULL, NULL );
        return;
}
LPDIRECT3DTEXTURE8 LoadTexture(char *filename)
{
     LPDIRECT3DTEXTURE8 pd3dTexture;
     D3DCOLOR colorkey = 0xFF000000; 
     D3DXIMAGE_INFO SrcInfo;   
     D3DXCreateTextureFromFileEx(dx8._pd3dDevice,filename,0,0,1,0,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, 
          colorkey, &SrcInfo , NULL, &pd3dTexture);

          return pd3dTexture;
}  

Share this post


Link to post
Share on other sites
How do i release it then? Is there a ReleaseTexture? If i try to make the texture variable global and only load it once, i get an exception error claiming that "texture is already in use can''t access it". Kind of stumped.

Share this post


Link to post
Share on other sites
Yikes!

No, don''t load your texture every frame and don''t release every frame either. Something like this:

Initialization:
Load your texture
Do whatever other setup

On Each Frame:
pDevice->SetTexture(0, Texture);
Draw whatever...

At the End:
Texture->Release();
Do whatever shutdown

I can''t tell from your code why you''d get that exception.

Share this post


Link to post
Share on other sites
Dont put your texture loading code inside of the drawscene function that will be run throughout the whole app, you could put it inside of your loadtexture function, because what your doing is causing the mem prob inside of that block you have there.
You could try this :


    
LPDIRECT3DTEXTURE8 texture; //MAKE SURE THIS IS GLOBAL

void Render(){ if( dx8._pd3dDevice == NULL) return; dx8._pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 ); dx8._pd3dDevice->BeginScene(); DrawScene(); blocks.showpiece(); dx8._pd3dDevice->EndScene(); dx8._pd3dDevice->Present( NULL, NULL, NULL, NULL );}void DrawScene()


{ BltSpriteEx( NULL, texture, NULL, NULL );
return;
}
texture = LoadTexture("single.bmp");
LPDIRECT3DTEXTURE8 LoadTexture(char *filename){ LPDIRECT3DTEXTURE8 pd3dTexture; D3DCOLOR colorkey = 0xFF000000; D3DXIMAGE_INFO SrcInfo; D3DXCreateTextureFromFileEx(dx8._pd3dDevice,filename,0,0,1,0,D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, colorkey, &SrcInfo , NULL, &pd3dTexture);
return pd3dTexture;
}








Sorry the code is sloppy hope oyu can catch my jift cause i'm coding on my game as well.

BTW Release the variable when your done with it with
texture->Release(); texture = 0;


Eric Wright o0Programmer0o






[edited by - KingsRevenge on July 24, 2002 12:47:02 AM]

[edited by - KingsRevenge on July 25, 2002 1:16:47 AM]

Share this post


Link to post
Share on other sites
Thanks! I figured it out before you guys responded but thanks for the help anyways. Looking at it again I thought it was the loadtexture function. Just having that program running for 10 seconds ate up 100megs of ram. GOODLORD!!!!

Share this post


Link to post
Share on other sites