Jump to content
  • Advertisement
Sign in to follow this  
215648

vector subscript out of range

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

void Terrain::BuildSubMesh(RECT& R, Vertex::Basic32* gridVerts)
{
SubMesh m;
 
std::vector<Vertex::Basic32> tempVerts(SubMesh::NUM_VERTICES);
std::vector<DWORD> tempIndices(SubMesh::NUM_INDICES);
 
int e = 0; 
for(int i = R.top; i <= R.bottom; ++i)
{
for(int j = R.left; j <= R.right; ++j)
{
 
tempVerts[e++] = gridVerts[i*mInfo.NumCols+j];
 
}
}
 
 
 
XMFLOAT3 vMinf3(+MathHelper::Infinity, +MathHelper::Infinity, +MathHelper::Infinity);
XMFLOAT3 vMaxf3(-MathHelper::Infinity, -MathHelper::Infinity, -MathHelper::Infinity);
 
XMVECTOR vMin = XMLoadFloat3(&vMinf3);
XMVECTOR vMax = XMLoadFloat3(&vMaxf3);
for(UINT i = 0; i < SubMesh::NUM_VERTICES; ++i)
{
XMVECTOR P = XMLoadFloat3(&tempVerts[i].Pos);
 
vMin = XMVectorMin(vMin, P);
vMax = XMVectorMax(vMax, P);
}
 
XMStoreFloat3(&m.box.Center, 0.5f*(vMin+vMax));
XMStoreFloat3(&m.box.Extents, 0.5f*(vMax-vMin)); 
 
 
// Iterate over each quad and compute indices.
UINT k = 0;
for(UINT i = 0; i < SubMesh::NUM_ROWS; ++i)
{
for(UINT j = 0; j < SubMesh::NUM_COLS; ++j)
{
 
static const int n = SubMesh::NUM_COLS;
 
   tempIndices[k]   = i*n+j;
tempIndices[k+1] = i*n+j+1;
tempIndices[k+2] = (i+1)*n+j;
 
tempIndices[k+3] = (i+1)*n+j;
   tempIndices[k+4] = i*n+j+1;
tempIndices[k+5] = (i+1)*n+j+1;
 
 
k += 6; // next quad
}
}
 
D3D11_BUFFER_DESC vbd;
    vbd.Usage = D3D11_USAGE_IMMUTABLE;
vbd.ByteWidth = sizeof(Vertex::Basic32) * SubMesh::NUM_VERTICES;
    vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vbd.CPUAccessFlags = 0;
    vbd.MiscFlags = 0;
 
    D3D11_SUBRESOURCE_DATA vinitData;
vinitData.pSysMem = &tempVerts[0];
 
HR(pDevice->CreateBuffer(&vbd, &vinitData, &m.VertexBuffer));
 
 
 
D3D11_BUFFER_DESC ibd;
    ibd.Usage = D3D11_USAGE_IMMUTABLE; 
ibd.ByteWidth = sizeof(DWORD) * SubMesh::NUM_INDICES;
    ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
    ibd.CPUAccessFlags = 0;
    ibd.MiscFlags = 0;
 
D3D11_SUBRESOURCE_DATA iinitData;
iinitData.pSysMem = &tempIndices[0];
 
HR(pDevice->CreateBuffer(&ibd, &iinitData, &m.IndexBuffer)); 
 
mSubMesh.push_back(m);
 
}

Why do i keep getting that?

I've confirmed that the problem is only in that code.

Edited by newtechnology

Share this post


Link to post
Share on other sites
Advertisement

By a quick look I'd suggest checking the loop conditions:

 

for(int i = R.top; i <= R.bottom; ++i)
{
for(int j = R.left; j <= R.right; ++j)
{ 
 ... 
}
}

 

maybe <= should be < ? 

 

Cheers!

Share this post


Link to post
Share on other sites

you can ignore because I finally after a lot of work, have implemented frustum culling by subdividing mesh and computing AABB for each and then doing AABB-Frustum intersection.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!