C++ Access violation writing location in for loop

-1

I was trying to make a Bounding Box work in order to implement frustrum culling in my engine. But as soon as i run the solution, an Access violation run time error appears in the transform function of the Bounding Box.

void BoundingBox::Transform(D3DXVECTOR3 pos, D3DXVECTOR3 rot, D3DXVECTOR3 sca) {

D3DXQUATERNION rotationQuaternion;

D3DXMatrixTransformation(&mat, NULL, NULL, &sca, NULL, 
    D3DXQuaternionRotationYawPitchRoll(&rotationQuaternion, 
    D3DXToRadian(rot.x), D3DXToRadian(rot.y), D3DXToRadian(rot.z)), &pos);

    for (int k = 0; k < 8; k++)
    {
        D3DXVec3Transform(&transVertex[k], &vertexes[k], &mat);

        /*this->*/xMin = min(transVertex->x, /*this->*/xMin);
        /*this->*/yMin = min(transVertex->y, /*this->*/yMin);
        /*this->*/zMin = min(transVertex->z, /*this->*/zMin);

        /*this->*/xMax = max(transVertex->x, /*this->*/xMax);
        /*this->*/yMax = max(transVertex->y, /*this->*/yMax);
        /*this->*/zMax = max(transVertex->z, /*this->*/zMax);
    }}

Anyone knows why this happens?

Here is what the error says: "Exception thrown at 0x0F5E20E6 (D3DX9_43.dll) in bushRanger.exe: 0xC0000005: Access violation writing location 0x00000038."

c++
directx
asked on Stack Overflow May 23, 2018 by Rodrigo Diaz

1 Answer

1

I found what happened, the camera makes the frustrum but it doesn't have a bounding box, and it still uses the same Move() function as the rest of the composites.

    void Composite::Move(D3DXVECTOR3 trasl, D3DXVECTOR3 escal, D3DXVECTOR3 rot) 
{
Component::Move(trasl, escal, rot);
/*D3DXMATRIX rotMat = rotXMat * rotYMat * rotZMat;
thyMatrix = scaMat * rotMat * transMat;*/
D3DXQUATERNION rotationQuaternion;
D3DXMatrixTransformation(&thyMatrix, NULL, NULL, &escal, NULL, D3DXQuaternionRotationYawPitchRoll(&rotationQuaternion, D3DXToRadian(rot.x), D3DXToRadian(rot.y), D3DXToRadian(rot.z)), &trasl);
laCajita->Transform(_trasl, _escal, _rot); // and here is a non existant bounding box
UpdateBoundingBox();
}

Here when it touched the Move function of the Camera, who is a composite, it calls a non existant bounding box.

Well, people, thanks for the help in the comments, i will be more attentive with the debbugger from now on before posting a question.

answered on Stack Overflow May 23, 2018 by Rodrigo Diaz

User contributions licensed under CC BY-SA 3.0