Skip to main content
gamedev.net
🔒 Locked

problems with std::vector [solved]

Started by ProgrammingNerd Aug 7, 2005 at 1:49 PM 2 replies 1.2k views
Original Post
ProgrammingNerd
ProgrammingNerd
I created a simple heightmap displayer in vc++ 6.0 in directx 9.0b. I got the latest version of the sdk and set up vc++ 2005. I'm using std::vector to store the heightmap data. I keep getting an assertion that the data is out of bounds. I did some debugging and found out that the following is making the assertion: line 774: #if _HAS_ITERATOR_DEBUGGING if (size() <= _Pos) { _DEBUG_ERROR("vector subscript out of range"); _SCL_SECURE_OUT_OF_RANGE; } #endif /* _HAS_ITERATOR_DEBUGGING */ All of my code was working perfectly in vc++ 6.0. Please help. If you need some example code, ask. Thanks, ProgrammingNerd [Edited by - ProgrammingNerd on August 7, 2005 2:43:26 PM]
dave
dave
Post the code that uses the vector, the code that is before u jump into the vector. It won't be the vector.

ace
ProgrammingNerd
ProgrammingNerd
Here's the code where it fails. Everything else works before it, and I checked to make sure that it is valid data. It is.

bool CSWGHeightMapTerrain::GenTexture(D3DXVECTOR3* directionToLight){	HRESULT hr = 0;	int texWidth  = NumCellsPerRow;	int texHeight = NumCellsPerCol;	hr = D3DXCreateTexture(		m_pD3DDevice,		texWidth, texHeight,		0,		0,		D3DFMT_X8R8G8B8,		D3DPOOL_MANAGED, &m_pTerrainTexture);	if(FAILED(hr))		return false;	D3DSURFACE_DESC textureDesc; 	m_pTerrainTexture->GetLevelDesc(0, &textureDesc);	if( textureDesc.Format != D3DFMT_X8R8G8B8 )		return false;			D3DLOCKED_RECT lockedRect;	m_pTerrainTexture->LockRect(0, &lockedRect, 0, 0);	DWORD* imageData = (DWORD*)lockedRect.pBits;	for(int i = 0; i < texHeight; i++)	{		for(int j = 0; j < texWidth; j++)		{			D3DXCOLOR c;			float height = (float)GetHeightmapEntry(i, j) / HeightScale;			if( (height) < 42.5f ) 		 c = BeachSand;			else if( (height) < 85.0f )	 c = LightYellowGreen;			else if( (height) < 127.5f ) c = PureGreen;			else if( (height) < 170.0f ) c = DarkYellowGreen;			else if( (height) < 212.5f ) c = DarkBrown;			else	                     c = White;						imageData[i * lockedRect.Pitch / 4 + j] = (D3DCOLOR)c;		}	}	m_pTerrainTexture->UnlockRect(0);	if(!LightTerrain(directionToLight))	{		::MessageBox(0, "lightTerrain() - FAILED", 0, 0);		return false;	}		hr = D3DXFilterTexture(		m_pTerrainTexture,		0,		0,		D3DX_DEFAULT);	if(FAILED(hr))	{		::MessageBox(0, "D3DXFilterTexture() - FAILED", 0, 0);		return false;	}	return true;
ProgrammingNerd
ProgrammingNerd
I solved it, a dumb bounds checking error. It's weird why this worked in vc++ 6, but not here.

Thanks for your help.

Topic Locked

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

Sign in to reply to this topic.