我对变量有一个非常奇怪的问题。在 OPENGL 渲染循环中进行几次调用后,一个变量会verticesSize
无任何原因地更改其值 (),而第二个变量 (verticesSize2) 不会... . 我如何命名第一个变量并不重要,它总是改变它的值,所以它一定是内存问题,但我不知道是什么导致它。有任何想法吗?
cpp。文件
void CosmicBody::InitShape(unsigned int uiStacks, unsigned int uiSlices, float fA, float fB, float fC)
{
float tStep = (Pi) / (float)uiSlices;
float sStep = (Pi) / (float)uiStacks;
float SlicesCount=(Pi+0.0001)/tStep;
float StackCount=(2*Pi+0.0001)/sStep;
this->verticesSize=((int) (SlicesCount+1) * (int) (StackCount+1))*2;
this->verticesSize2=((int) (SlicesCount+1) * (int) (StackCount+1))*2;
}
主文件
#include ....
CosmicBody one;
void renderScene(void)
{
std::cout<<one.verticesSize<<endl;
std::cout<<one.verticesSize2<<endl;
fps.calculateFPS(clock.elapsedTime);
glutSwapBuffers();
}
EDIT
OK 我发现是哪一行导致这个函数函数的问题导致sprintf
程序运行不正确。为什么另一个类的函数会导致这个?无效 FpsCalc::calculateFPS(unsigned int currentTime) {
frameCount++;
int timeInterval = currentTime - previousTime;
if(timeInterval > 1000)
{
float fps = frameCount / (timeInterval / 1000.0f);
previousTime = currentTime;
frameCount = 0;
sprintf(this->fps,"%f",fps); //this line makes mess
}
}
#ifndef FPSCALC_H
#define FPSCALC_H
class FpsCalc
{
private:
int frameCount;
float previousTime;
public:
FpsCalc();
void calculateFPS(unsigned int currentTime);
char fps[5];
~FpsCalc(){};
};
#endif