| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Noob Memory Leak (?) problem
Hi All
First off, I suck at C, so bear with me please. I need to do an OpenGL project which was going fine until I ran into a weird problem. After adding some code which initialises an array, my program stopped doing anything. If I ran it, it immediatly terminated. No error/warning message, nothing. I tried tracing my problems, but as soon as I entered a simple cerr the program worked again, 100%. As long as I leave the cerr there, it works, if I comment it out, it doesn't work anymore. The only thing I can think of is a pointer problem, but I can't see where I went wrong. The only pointer I have is the one in the code below: Ps. Don't worry about the OpenGL calls, their all pretty standard. Code:
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("OpenGL");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutSpecialFunc(specialKeys);
glutIdleFunc(idle);
cerr << "HELP ME!!!" << endl; // The cerr which fixed everything!
initialise();
glutMainLoop();
}
void initialise()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
loadTextures();
xLook = sin(angle * M_PI / 180);
zLook = cos(angle * M_PI / 180);
yPos = LOOKHEIGHT;
// Initialise PoolMap
// Commenting out this the part below also fixes the problem!
for (int x = 0; x < POOLWIDTH; ++x)
{
for (int z = 0; z < POOLWIDTH; ++z)
{
waterMap[z * POOLWIDTH + x] = getRandomFloat(-0.05, 0.05);
}
}
idleCount = 0;
}
float getRandomFloat(float low, float high)
{
return ((float)rand() / (RAND_MAX + 1.0)) * (high - low) + low;
}
float waterMap[POOLWIDTH * POOLWIDTH];
Any help will be appreciated. Thank you |
|
#2
|
|||||
|
|||||
|
Some thoughts, though I'm not sure if any are related to your problem:
First, in function initialise(), depends on which compiler you're using (more specifically, are you coding C or C++. If C, it may be that your compiler doesn't like the int x and int z declarations int the for loop. Officially, in ANSI-C, all declarations have to be done before any other statements in a functions, so you might want to change that function to: c Code:
Another thing I noticed, which should give you a warning, is that your int main() doesn't give a return value. End it with 'return 0;' Though this should not be related in any way to your troubles.
__________________
This is my code. Is it not nifty? "The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools." ---Douglas Adams Join the Itsacon fanclub! Zero Tolerance: Spammers banned so far: 275
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Noob Memory Leak (?) problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|