【发布时间】:2011-11-05 02:11:58
【问题描述】:
我有全局变量:
point4 * mypoints;
color4 * mycolors;
还有一段代码是函数drawPlyFiles的一部分
vector<point4> retpolys;
retpolys.resize(polynum * 3);
GLint polyx, polyy, polyz;
for (int i = 0; i < polynum; i++)
{
inStream >> polyx;
inStream >> polyx >> polyy >> polyz;
//cout << "x: " << polyx << " y: " << polyy << " z: " << polyz << "\n";
retpolys[i*3] = retVerts[polyx];
retpolys[(i*3) + 1] = retVerts[polyy];
retpolys[(i*3) + 2] = retVerts[polyz];
//retpolys[i] = point4( polyx, polyy, polyz, 1.0 );
}
mypoints = &retpolys[0];
return true;
从代码中删除的重要部分是我将全局 mypoints(array) 设置为等于 retpolys(vector)。 Retpolys 被来自 for 循环的数据填充。当我调试时,retpolys 中的所有数据都很好。 (retVerts 是point4的向量)
稍后在我的主初始化函数中运行:
drawPlyFile("ply_files/airplane.ply");
//colorcube();
point4 temp = mypoints[1];
int thissize = sizeof(mypoints)/sizeof(mypoints[0]);
for (int i = 0; i < thissize; i++)
{
mycolors[i] = color4( 0.0, 0.0, 0.0, 1.0 );
}
代码编译得很好,但我有一个运行时异常。我调试以发现问题。我在 drawPlyFiles 之后检查了 mypoints 的值,看起来它只包含一个指向 retpolys 开始位置的指针。但是,当我调试时,它不允许我查看数组的其他部分,只是第一个指针。(当我在函数中时,我可以看到 retpolys 的所有单独值)然后我检查这个大小的值,然后我得到一个像 -12894161 这样的数字,这没有意义,因为它应该是 mypoints 的大小。
我认为问题在于从 retpolys 到 mypoints 的转换,但我不知道如何修复它,或者即使那是错误的实际原因。有什么帮助吗?
附言我希望 mycolors 具有与 mypoints 相同数量的元素,并且所有 em 都是 color4( 0.0, 0.0, 0.0, 1.0 )
【问题讨论】: