Jump to content
  • Advertisement
Sign in to follow this  
Aph3x

OpenGL Crash most horrid!

This topic is 4434 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, Having fun with OpenGL texturing... When I run the code below to draw a sea plane in my world, after about a minute, I get a horrible crash whereby certain textures go corrupted and weird long things are drawn on the screen, followed by a machine freeze (i.e. like some nasty memory overwrite) Not nice. If I comment out the four glTexCoord2f calls though, everything is fine. Hmmm. Any ideas?! Some sort of illegal texture coords? Everything seems to draw ok before the crash...

const double KSquareSize = 1024.0f;
const int KTexScale = int(KSquareSize/64.0f);	// Texture scaling.
const float seaLevel = WORLD().SeaLevel() - camPos.y;
TPointf texOffset = WORLD().SeaTextureOffset();	// sin offset for swirly sea effect

// Find top-left of current square of KSquareSize units.
int xtl = int(camPos.x / KSquareSize);
if (camPos.x < 0) xtl--;
int ztl = int(camPos.z / KSquareSize);
if (camPos.z < 0) ztl--;

// Calc offset so sea seems to stay still when camera moves.
const float offsetX = camPos.x - ((xtl*KSquareSize));
const float offsetZ = camPos.z - ((ztl*KSquareSize));

if (mProceduralSeaMode == ESeaDrawFlat)
{
	// Draw the 9 squares surrounding the camera.
	for (int x=-KSquareSize ; x<=+KSquareSize ; x+=KSquareSize)
	{
		const float vx = x-offsetX;
		for (int z=-KSquareSize ; z<=+KSquareSize ; z+=KSquareSize)
		{
			const float vz = z-offsetZ;
			glBegin(GL_TRIANGLE_STRIP);
				glTexCoord2f(texOffset.x, texOffset.y);
				glVertex3f(vx, seaLevel, vz);

				glTexCoord2f(texOffset.x, KTexScale+texOffset.y);
				glVertex3f(vx, seaLevel, vz+KSquareSize);

				glTexCoord2f(KTexScale+texOffset.x, texOffset.y);
				glVertex3f(vx+KSquareSize, seaLevel, vz);

				glTexCoord2f(KTexScale+texOffset.x, KTexScale+texOffset.y);
				glVertex3f(vx+KSquareSize, seaLevel, vz+KSquareSize);
			glEnd();
		}
	}
}




(Gfx: XFX Nvidia 7900 GT, manufacturers drivers btw)

Share this post


Link to post
Share on other sites
Advertisement
If I had to guess, I'd say that the data for the texcoords are being overwritten by some other part of the program. I'd recommend integrating a memory manager such as fluidstudio's mmgr (see google) to see if you can find the leak/overrun.

Sorry, also, I didn't look at your code, but by the description it sounds like this may help.

~zix

Share this post


Link to post
Share on other sites
That looks like a worthy inclusion anyway - I'll give it a go, thanks...

I'm beginning to suspect a driver problem though, as the machine crashes afterwards :o

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
bad guess maybe ..
but when i use tri strips .. i usually pass 2 vertices between the begin/end
statements.
i dunno maybe u can pass more than 2!
what say ?

Share this post


Link to post
Share on other sites
I've had the same thing happen before. It was that my program was not only overwriting the texcoords, but also parts of the textures themselves, resulting in some REALLY wacky textures for a second, then a crash. The way I solved this was with a texture manager; it's essentially an STL vector that contains texture objects and allocates memory based on the size of the texture and the size of the object itself (I encapsulated texture data and functions to manipulate them into one class). This ensured that memory was only being written in the right places, and that nothing would overwrite it (at least I believe so; that was the only thing I changed, and it worked perfectly). Of course, this was a hacked-together engine, so maybe it just sort of worked for no reason :P.

Hope that helps,
Aviosity

Share this post


Link to post
Share on other sites
hmm having some trouble getting MMGR to compile with my project - this could take some time!

@aviosity: I use a texture manager already (the one from Gamedev's hallowed pages no less! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!