   D3DXComputeBoundingBox problem
  I have a cube built manually in code (below).  After building the VB, I compute the bounding box.  When I run my code, I expect that m_boxMin should = {-50, -50, -50} and that m_boxMax should = {50, 50, 50}.  But, the results I am getting is m_boxMin = {-50, -50, -50} and m_boxMax = {3.45679e+031, 50, 3.45819e+031}.  Does anyone see what I'm missing or what I'm doing wrong?// Create Vertex bufferif(FAILED(m_pD3DDevice->CreateVertexBuffer(sizeof(CubeVertex) * 36, 0, CubeVertex::FVF,D3DPOOL_DEFAULT, &m_pVB, NULL))){//m_App->AppError(true, "Error creating vertex buffer!");}CubeVertex* vertices = 0;m_pVB->Lock(0, 0, (void**)&vertices, 0);// frontvertices[0]  = CubeVertex( -50.0f, -50.0f, -50.0f,  0.0f,  0.0f, -1.0f, 0.0f, 1.0f );vertices[1]  = CubeVertex( -50.0f,  50.0f, -50.0f,  0.0f,  0.0f, -1.0f, 0.0f, 0.0f );vertices[2]  = CubeVertex(  50.0f,  50.0f, -50.0f,  0.0f,  0.0f, -1.0f, 1.0f, 0.0f );vertices[3]  = CubeVertex( -50.0f, -50.0f, -50.0f,  0.0f,  0.0f, -1.0f, 0.0f, 1.0f );vertices[4]  = CubeVertex(  50.0f,  50.0f, -50.0f,  0.0f,  0.0f, -1.0f, 1.0f, 0.0f );vertices[5]  = CubeVertex(  50.0f, -50.0f, -50.0f,  0.0f,  0.0f, -1.0f, 1.0f, 1.0f );// backvertices[6]  = CubeVertex(  50.0f, -50.0f,  50.0f,  0.0f,  0.0f,  1.0f, 1.0f, 1.0f );vertices[7]  = CubeVertex(  50.0f,  50.0f,  50.0f,  0.0f,  0.0f,  1.0f, 1.0f, 0.0f );vertices[8]  = CubeVertex( -50.0f, -50.0f,  50.0f,  0.0f,  0.0f,  1.0f, 0.0f, 1.0f );vertices[9]  = CubeVertex(  50.0f,  50.0f,  50.0f,  0.0f,  0.0f,  1.0f, 1.0f, 0.0f );vertices[10] = CubeVertex( -50.0f,  50.0f,  50.0f,  0.0f,  0.0f,  1.0f, 0.0f, 0.0f );vertices[11] = CubeVertex( -50.0f, -50.0f,  50.0f,  0.0f,  0.0f,  1.0f, 0.0f, 1.0f );// leftvertices[12] = CubeVertex( -50.0f, -50.0f, -50.0f, -1.0f,  0.0f,  0.0f, 1.0f, 1.0f );vertices[13] = CubeVertex( -50.0f,  50.0f,  50.0f, -1.0f,  0.0f,  0.0f, 0.0f, 0.0f );vertices[14] = CubeVertex( -50.0f,  50.0f, -50.0f, -1.0f,  0.0f,  0.0f, 1.0f, 0.0f );vertices[15] = CubeVertex( -50.0f, -50.0f, -50.0f, -1.0f,  0.0f,  0.0f, 1.0f, 1.0f );vertices[16] = CubeVertex( -50.0f, -50.0f,  50.0f, -1.0f,  0.0f,  0.0f, 0.0f, 1.0f );vertices[17] = CubeVertex( -50.0f,  50.0f,  50.0f, -1.0f,  0.0f,  0.0f, 0.0f, 0.0f );// rightvertices[18] = CubeVertex(  50.0f,  50.0f,  50.0f,  1.0f,  0.0f,  0.0f, 0.0f, 0.0f );vertices[19] = CubeVertex(  50.0f, -50.0f,  50.0f,  1.0f,  0.0f,  0.0f, 0.0f, 1.0f );vertices[20] = CubeVertex(  50.0f, -50.0f, -50.0f,  1.0f,  0.0f,  0.0f, 1.0f, 1.0f );vertices[21] = CubeVertex(  50.0f,  50.0f, -50.0f,  1.0f,  0.0f,  0.0f, 1.0f, 0.0f );vertices[22] = CubeVertex(  50.0f,  50.0f,  50.0f,  1.0f,  0.0f,  0.0f, 0.0f, 0.0f );vertices[23] = CubeVertex(  50.0f, -50.0f, -50.0f,  1.0f,  0.0f,  0.0f, 1.0f, 1.0f ); // topvertices[24] = CubeVertex( -50.0f,  50.0f, -50.0f,  0.0f,  1.0f,  0.0f, 0.0f, 1.0f );vertices[25] = CubeVertex( -50.0f,  50.0f,  50.0f,  0.0f,  1.0f,  0.0f, 0.0f, 0.0f );vertices[26] = CubeVertex(  50.0f,  50.0f,  50.0f,  0.0f,  1.0f,  0.0f, 1.0f, 0.0f );vertices[27] = CubeVertex( -50.0f,  50.0f, -50.0f,  0.0f,  1.0f,  0.0f, 0.0f, 1.0f );vertices[28] = CubeVertex(  50.0f,  50.0f,  50.0f,  0.0f,  1.0f,  0.0f, 1.0f ,0.0f );vertices[29] = CubeVertex(  50.0f,  50.0f, -50.0f,  0.0f,  1.0f,  0.0f, 1.0f, 1.0f );// bottomvertices[30] = CubeVertex(  50.0f, -50.0f, -50.0f,  0.0f, -1.0f,  0.0f, 1.0f, 1.0f );vertices[31] = CubeVertex(  50.0f, -50.0f,  50.0f,  0.0f, -1.0f,  0.0f, 1.0f, 0.0f );vertices[32] = CubeVertex( -50.0f, -50.0f, -50.0f,  0.0f, -1.0f,  0.0f, 0.0f, 1.0f );vertices[33] = CubeVertex(  50.0f, -50.0f,  50.0f,  0.0f, -1.0f,  0.0f, 1.0f, 0.0f );vertices[34] = CubeVertex( -50.0f, -50.0f,  50.0f,  0.0f, -1.0f,  0.0f, 0.0f, 0.0f );vertices[35] = CubeVertex( -50.0f, -50.0f, -50.0f,  0.0f, -1.0f,  0.0f, 0.0f, 1.0f );m_pVB->Unlock();Computing bounding box:D3DXComputeBoundingBox((D3DXVECTOR3*)m_pVB, 36, sizeof(CubeVertex), &m_boxMin, &m_boxMax)
  You seem to be casting a pointer to a Vertex Buffer to a pointer to an array of D3DXVECTOR3s.Try locking the vertex buffer with Read-Only, and passing the pointer you get from the lock operation as the first argument in the function.Hope this helps.   ;Quote:Original post by sirobYou seem to be casting a pointer to a Vertex Buffer to a pointer to an array of D3DXVECTOR3s.Try locking the vertex buffer with Read-Only, and passing the pointer you get from the lock operation as the first argument in the function.Hope this helps.Thanks for the reply.  I'm writing directly to the locked vertex buffer, so I can't lock it with read-only.   ;  Sorry, I guess I wasn't clear enough:D3DXComputeBoundingBox((D3DXVECTOR3*)m_pVB, 36, sizeof(CubeVertex), &m_boxMin, &m_boxMax)bold section seems like a bad idea.   ;Quote:Original post by sirobSorry, I guess I wasn't clear enough:D3DXComputeBoundingBox((D3DXVECTOR3*)m_pVB, 36, sizeof(CubeVertex), &m_boxMin, &m_boxMax)bold section seems like a bad idea.Thanks a lot, I changed "m_pVB" to "vertices" and it worked perfectly.   