• Advertisement
Sign in to follow this  

Textures causing out of memory

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

Hi all, I'm loading 6 textures, each is 512x512 of type bmp size are 769k each. These load ok, but when I come to do a new on my HUD object, it fails. Example :
	gpSkyBox = new CSkyBox( CSGDirect3DManager::GetInstance()->GetDevice() );
	gpSkyBox->Initialise();

	gpHud = new CHud( CSGDirect3DManager::GetInstance()->GetDevice() );
	gpHud->SetUpCameraView();
	gpHud->SetTexture( "..\\..\\Bitmaps\\hud2.bmp", 0xFFFFFFFF );
	gpHud->InitialiseGeometry();




The skybox initialise makes a call to this method to load the textures:
HRESULT CSkyBox::LoadSkyBoxTextures(char **pFilenames )
{
	HRESULT r = 0;
	for ( int i = 0; i < 6; i++ )
	{
		r = D3DXCreateTextureFromFile( m_pDevice, pFilenames[i], &m_pSkyBoxTexture[i]);
		if(FAILED(r))
			return E_FAIL;
	}
	return r;
}

As soon as the new on CHud is called, it returns NULL, if I ommit the gpSkyBox->Initialise() which loads up the textures for the skybox it works. Am I doing something obvious wrong ? Just FYI if I do the above like this :
	gpHud = new CHud( CSGDirect3DManager::GetInstance()->GetDevice() );
	gpHud->SetUpCameraView();
	gpHud->SetTexture( "..\\..\\Bitmaps\\hud2.bmp", 0xFFFFFFFF );
	gpHud->InitialiseGeometry();

	gpSkyBox = new CSkyBox( CSGDirect3DManager::GetInstance()->GetDevice() );
	gpSkyBox->Initialise();



It all works (i.e loading the skybox after the hud ) ???? Any help is much appreciated. Steve

Share this post


Link to post
Share on other sites
Advertisement
Without any details on your screen size, vertex buffer sizes, etc, and details of your cards, what kind of help are you looking for?

How much memory does you card have? Have you tried to figure out how much you're using?

. 512 width
* 512 height
* 4 (bytes per pixel)
* 1.33 (mipmaps)
* 6 number of textures
-----
8,388,587

There are overheads of headers, etc, so let's say 8.4MB.
How big is your back/front/depth buffers?

Lets assume you're doing 1024x768
. 1024
* 768
* 4
* 3
---------
9,437,184

Just over 16 Megs so far... Perhaps you're running 800x600, and just squeeze into a 16MB cards.

Do you have AA enabled? That affects the back/depth buffer sizes (*2 or *4).

You're probably loading your textures are DEFAULT instead of MANAGED. MANAGED allows D3D to swap the textures out of video RAM and put new ones in as needed, effectively giving your virtual memory on your GPU... a bit slow, but better than a crash.

Share this post


Link to post
Share on other sites
I have 256mb video memory. I'm loading textures for the HUD as MANAGED and loading textures for the skybox using D3DXCreateTextureFromFile, so I can't specify how these textures are 'managed', or can I ?

I have now found the problem, it was a case of bad coding by me, my skybox is made up of 24 vertices, this is what I had in my code :


struct SKYBOXVERTEX {
SKYBOXVERTEX() { }
D3DXVECTOR3 m_Position;
float m_tu, m_tv;
};

#define CUSTOM_SKYVERTEX (D3DFVF_XYZ |D3DFVF_TEX1)

class CSkyBox : public CShape
{
public:
CSkyBox( LPDIRECT3DDEVICE9 pDevice );
~CSkyBox(void);
void Initialise();
void Render();
protected:
virtual HRESULT LoadSkyBoxTextures( char **pFilenames = NULL );

private:
LPDIRECT3DTEXTURE9 m_pSkyBoxTexture[5];

char** m_pFilenames;

enum SkyBoxTextures { Left = 0, Right, Top, Bottom, Front, Back };

SKYBOXVERTEX m_vert[6];
};


Can you spot the bad mistake ?! Yes, m_vert should be 24, duh!

Anyway, thanks Namethatnobodyelsetook for your help, I appreciate it.

Kind regards,
Steve

Share this post


Link to post
Share on other sites
One more think that could crash the program if you haven't fixed it by now.

You load in 6 textures but only allocate space for 5 texture pointers.

LPDIRECT3DTEXTURE9 m_pSkyBoxTexture[5];

Share this post


Link to post
Share on other sites
Eriko, indexes start at zero I believe, so 0-5 is 6.

Thanks,
Steve

Share this post


Link to post
Share on other sites
an array[5] is 0-4, if you actually use a 5th index you are accessing memory that is out of bounds.

the number in the brackets should be the number of items you need.
textures[6], and you access them 0-5

LPDIRECT3DTEXTURE9 m_pSkyBoxTexture[5]; is giving you 5 textures.

when this loop gets to the 5th element, it is out of bounds.

for ( int i = 0; i < 6; i++ )

m_pSkyBoxTexture[5] is 5 elements, 0-4

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement