编辑:已解决
Win32Project2.exe 中 0x00F25625 处的未处理异常:0xC0000005:访问冲突读取位置 0x00000000。
那是我的问题。我使用 MS Visual Studio Express 2012。
此错误是由这一行引发的
for(int i=1;i<maxLevel;i++)
korona.push_back(Level(this,ratio*korona[i-1].l,i));
那是科罗纳宣言。
std::vector <Level> korona;
和“水平”类:
class Level{
public:
float l;
float color[3];
char lvl;
std::vector <Stick> sticks;
Tree *S;
Level(Tree *S,float l);
Level(Tree *S,float l,char lvl);
~Level();
void Change(float h);
};
最后 Level 构造函数:
Level::Level(Tree *S,float l,char lvl){
this->l=l;
this->lvl=lvl;
for(int i=0;i<3;i++)
this->color[i]=0.0;
this->S=S;
//sticks.resize(S->amount*S->korona[lvl-1].sticks.size());
for(unsigned int i=0;i<S->korona[lvl-1].sticks.size();i++){
float x=S->korona[lvl-1].sticks[i].x;
float Sx=S->korona[lvl-1].sticks[i].S->x;
float y=S->korona[lvl-1].sticks[i].y;
float Sy=S->korona[lvl-1].sticks[i].S->y;
float z=S->korona[lvl-1].sticks[i].z;
float Sz=S->korona[lvl-1].sticks[i].S->z;
float siny,cosy;
if(l!=0){
siny=sqrt((x-Sx)*(x-Sx)+(z-Sz)*(z-Sz))/S->korona[lvl-1].l;
cosy=(y-Sy)/S->korona[lvl-1].l;
}
//else {siny=0;cosy=1;}
float cosx,sinx;
float co=cos(S->angle);
float si=sin(S->angle);
if(sqrt((x-Sx)*(x-Sx)+(z-Sz)*(z-Sz))==0){cosx=1;sinx=0;}
else {
cosx=(Sx-x)/sqrt((x-Sx)*(x-Sx)+(z-Sz)*(z-Sz));
sinx=(z-Sz)/sqrt((x-Sx)*(x-Sx)+(z-Sz)*(z-Sz));
}
float lng=S->ratio*this->l;
for(int j=0;j<S->amount;j++){
float a=lng*co*cos(360.0f/S->amount*j*rad)*cosy-lng*si*siny;
float b=lng*co*cos(360.0f/S->amount*j*rad)*siny+lng*si*cosy;
float c=lng*co*sin(360.0f/S->amount*j*rad);
sticks.push_back(Stick(&(S->korona[lvl-1].sticks[i]),
c*sinx+a*cosx+S->korona[lvl-1].sticks[i].x,
b+S->korona[lvl-1].sticks[i].y,
c*cosx-a*sinx+S->korona[lvl-1].sticks[i].z));
}
}
}
我至少工作了几个小时。我累了
*编辑: *好的,我做到了。有些计算是错误的。:/