Jump to content
  • Advertisement
Sign in to follow this  
ProgrammingNerd

problems with std::vector [solved]

This topic is 4847 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 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]

Share this post


Link to post
Share on other sites
Advertisement
Post the code that uses the vector, the code that is before u jump into the vector. It won't be the vector.

ace

Share this post


Link to post
Share on other sites
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;

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!