Texture loading error

Started by
2 comments, last by smally 16 years, 2 months ago
Ok, I decided to re-design how my engines texture are handled. However I've come across a problem with the loading of the texture. It crashes during and the call stack points at m_texVector.push_back(tex) and I can't see what I have done wrong. m_texVector is declared as:
std::vector<LPDIRECT3DTEXTURE9> m_texVector;
the problem points to here:

bool Texture::LoadTexture(const std::string filename)
{
	bool fQuit = false;
	LPDIRECT3DTEXTURE9 tex = 0;

	while ( !fQuit )
	{
		HRESULT hr = D3DXCreateTextureFromFile(g_device, filename.c_str(), &tex);

		if ( SUCCEEDED(hr) )
		{
			m_texVector.push_back( tex );    // Error somehow!!!
			return true;
		}
		else
		{
			std::string errorMsg = "Cannot find texture: " + filename;
			int msg = MessageBox(0, errorMsg.c_str(), "Texture Error", MB_ABORTRETRYIGNORE);

			switch ( msg )
			{
			case IDABORT:
				fQuit = true;
				PostQuitMessage(0);
				break;
			case IDIGNORE:
				fQuit = true;
				break;
			default:
				break;
			}
		}
	}
	return false;
}

Advertisement
The most likely cause is that you've called your LoadTexture() on an invalid pointer. (Ex: didn't new the object.)
Are you declaring m_texVector as static? If so, it might be a static initialization dependency problem.
Quote:Original post by SiCrane
The most likely cause is that you've called your LoadTexture() on an invalid pointer. (Ex: didn't new the object.)


Ah yes, I got so caught up in the design I missed that, thanks

This topic is closed to new replies.

Advertisement