for循环

时间:2018-05-23 00:01:14

标签: c++ directx

我试图让一个Bounding Box工作,以便在我的引擎中实现frustrum剔除。但是一旦我运行解决方案,边界框的转换功能中就会出现Access违规运行时错误。

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);
    }}

任何人都知道为什么会这样?

以下是错误说明:“bushRanger.exe中的0x0F5E20E6(D3DX9_43.dll)抛出异常:0xC0000005:访问冲突写入位置0x00000038。”

1 个答案:

答案 0 :(得分:1)

我发现发生了什么,相机制作了截头体,但它没有边框,它仍然使用与其余复合材料相同的Move()函数。

    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();
}

当触摸Camera的Move功能时,它是一个复合物,它会调用一个不存在的边界框。

嗯,人们,感谢评论中的帮助,从发布问题开始,我将更加关注debbugger。