您好我有以下功能:
private BspFile.dleaf_t GetLeafForPoint(_vec3 point)
{
var node = 0;
BspFile.dnode_t pNode;
BspFile.dplane_t pPlane;
var d = 0.0f;
while (node >= 0)
{
pNode = Nodes[node];
pPlane = Planes[pNode.planenum];
d = point.x*pPlane.normal.x + point.y*pPlane.normal.y + point.z*pPlane.normal.z - pPlane.dist;
node = d > 0 ? pNode.children[0] : pNode.children[1];
}
if ((-node - 1) >= 0 && -node - 1 < Leafs.Length)
{
return Leafs[-node - 1];
}
else
{
BspFile.dleaf_t newLeaf = new BspFile.dleaf_t();
newLeaf.area = -1;
newLeaf.contents = 0;
return newLeaf;
}
}
如果我运行它,则以下行抛出一个ArrayOutOfIndex异常: 返回newLeaf;
我不知道为什么因为struct实例已经初始化并且某些值已经设置了......
感谢您的帮助