Crash most horrid!

Started by
4 comments, last by MGB 17 years, 10 months ago
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)
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
---------------------------------------------------Game Programming Resources, Tutorials, and Multimedia | Free Skyboxes
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
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 ?
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
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! :)

This topic is closed to new replies.

Advertisement