C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 27th, 2005, 08:23 AM
BadBoyZ BadBoyZ is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 2 BadBoyZ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 42 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old September 27th, 2005, 09:27 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 996 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 808001 Folding Title: Super Ultimate Folder - Level 2Folding Points: 808001 Folding Title: Super Ultimate Folder - Level 2Folding Points: 808001 Folding Title: Super Ultimate Folder - Level 2Folding Points: 808001 Folding Title: Super Ultimate Folder - Level 2Folding Points: 808001 Folding Title: Super Ultimate Folder - Level 2Folding Points: 808001 Folding Title: Super Ultimate Folder - Level 2Folding Points: 808001 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 5 m 52 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
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:
Original - c Code
  1. void initialise()
  2. {
  3.     int x, z;
  4.     glClearColor(0.0, 0.0, 0.0, 1.0);
  5.     glEnable(GL_DEPTH_TEST);
  6.     glEnable(GL_TEXTURE_2D);
  7.  
  8.     loadTextures();
  9.  
  10.     xLook = sin(angle * M_PI / 180);
  11.     zLook = cos(angle * M_PI / 180);
  12.     yPos = LOOKHEIGHT;
  13.  
  14.     // Initialise PoolMap
  15.     // Commenting out this the part below also fixes the problem!
  16.     for (x = 0; x < POOLWIDTH; ++x)
  17.     {
  18.         for (z = 0; z < POOLWIDTH; ++z)
  19.         {
  20.             waterMap[z * POOLWIDTH + x] = getRandomFloat(-0.05, 0.05);
  21.         }
  22.     }
  23.     idleCount = 0;
  24. }


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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Noob Memory Leak (?) problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT