Hi there
I am building a 3D game in C++ and openGl

I came to do a full test of my game the collision detection and things are finally approaching working fully.

When I run it it becomes very memory hungry and eats a few Gb of Ram and crashes after a few minutes it literally takes about 2mb+ of memory a second.

I have taken most of the stuff out out of the display to work out what it is.

I bought it down to the way I am drawing stuff. Without drawing my track it takes about 10MB of memory mainly due to it being black space with a few blocks and some variables in memory.

I'm guessing it might be because I am using variables in arrays to build my track? do I need to manaully tell it to destruct after?

I draw my walls like this

void Enviroment::drawWall(float wallPosition[], Boat_Pos playerBoat, float wallNormals1,float wallNormals2, float wallNormals3)
{

	
	

	glPushMatrix();

	glBegin(GL_POLYGON);
		glColor3f(0.7,0.7,0.7);
		glTexCoord2f(0,0); glVertex3f(wallPosition[0], 0, wallPosition[1]);
		glTexCoord2f(1,0); glVertex3f(wallPosition[0], 3, wallPosition[1]);
		glTexCoord2f(1,1); glVertex3f(wallPosition[2], 3, wallPosition[3]);
		glTexCoord2f(0,1); glVertex3f(wallPosition[2], 0, wallPosition[3]);
glEnd();



Collision::PointToPlaneTest(playerBoat,wallPosition[0],3,wallPosition[1],wallNormals1,wallNormals2,wallNormals3);
	
}

Can I destroy the memory at the bottom? Is it due to the arrays?

I am drawing it in the display by simply doing

Enviroment::drawWall(wall1,Player,finalWall1[0],finalWall1[1],finalWall1[2]);

The variables for the normals etc are all calculated in the init function and only run once. I have them still running and no memory is taken which confimrs this. Dows the computer allocate new memory every loop?

Many thanks

I have managed to narrow down the problem. If I take off the textures from my enviroment etc the application stops eating memory. Should I allocate textures in the Init function? Or am i doing something wrong?

P.S sorry if this is in the wrong part of the forum I assumed it was a C++ problem but know figure it might be a openGl problem.

Recommended Answers

All 2 Replies

Ok show us how/where you call the allocation for texture. Presumably, you only need to allocate once for the texture.

Ok show us how/where you call the allocation for texture. Presumably, you only need to allocate once for the texture.

Awsome thanks

I was loading it in the display so it was allocating new textur maps every frame.
Moving it so it only loads once has solved the issuse. Stupid mistake :). Sorry was experimenting with putting stuff in classes thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.