Skip to main content
gamedev.net
🔒 Locked

Program compiling acting funny..

Started by zix99 2 replies 600+ views
Original Post
zix99
zix99
Hello everyone My game is acting increadibly funny, seems it has a mind of it's own. I'm using VC++ 6, C++, with OpenGL, FMOD (for sound), and win32 API for the window. My problem is that the program crashes in a predictable, but to me not very logical manner. When compiling the program under DEBUG, and run from the IDE it works fine; when compiling the program under DEBUG and run from the exe it works fine; when compiling the program under RELEASE and run from the IDE it works fine, BUT, when compiling the program under RELEASE and run from the exe, it crashes with the error-report window, with not much other information other than it occured in the exe specifically (rather than a used dll). I put in manual debugging (in this case message boxes that popped up and intervals) to locate the error, found it, and it's even more suspicious. The program dies here:

void PLAYER::DrawPlayer(){
	MessageBox(NULL, "9.1.0", "DEBUG", MB_OK);
	if (visible==false)
		return;
	MessageBox(NULL, "9.1.0.1", "DEBUG", MB_OK);
	if (frame < 0.0f || frame > 197.0f)
		return;

	MessageBox(NULL, "9.1.1", "DEBUG", MB_OK);
	/*GLUquadric *quadric = gluNewQuadric();
	gluQuadricNormals(quadric, 1);
	
	glPushMatrix();
	glTranslatef(x,y,z);
	gluSphere(quadric, 0.5f, 5,5);
	glPopMatrix();

	gluDeleteQuadric(quadric);*/

	MessageBox(NULL, "9.1.2", "DEBUG", MB_OK);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, skin);
	MessageBox(NULL, "9.1.3", "DEBUG", MB_OK);
	glPushMatrix();
	glTranslatef(x,y,z);
	glRotatef(-(rotz-PID2)*DPI, 0,0,1);
	glScalef(0.008f, 0.008f, 0.008f);
	MessageBox(NULL, "9.1.4", "DEBUG", MB_OK);
	model->Draw(frame);
	glPopMatrix();
	MessageBox(NULL, "9.1.5", "DEBUG", MB_OK);

	//shadow
	glPushMatrix();
	glTranslatef(x,y,0.0f);

	MessageBox(NULL, "9.1.6", "DEBUG", MB_OK);
	glBindTexture(GL_TEXTURE_2D, shadowtex);
	MessageBox(NULL, "9.1.7", "DEBUG", MB_OK);
	glEnable(GL_BLEND);
	glDisable(GL_LIGHTING);
	glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0.5f, 0.5f, terr_GetHeight(x+0.5f, y+0.5f)+0.012f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, 0.5f, terr_GetHeight(x-0.5f, y+0.5f)+0.012f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, -0.5f, terr_GetHeight(x-0.5f, y-0.5f)+0.012f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0.5f, -0.5f, terr_GetHeight(x+0.5f, y-0.5f)+0.012f);
	glEnd();
	glDisable(GL_BLEND);
	glEnable(GL_LIGHTING);

	glPopMatrix();
	MessageBox(NULL, "9.1.8", "DEBUG", MB_OK);
}


void player_Draw(){
	MessageBox(NULL, "9.1.0.0.2", "DEBUG", MB_OK);
	for (int i=0; i<PLAYERAMT; ++i)
		player.DrawPlayer();
	MessageBox(NULL, "9.1.0.0.3", "DEBUG", MB_OK);
}

It gets to 9.1.0.0.2, goes into the loop, then calls the function DrawPlayer(), gets to 9.1.0, visible==false (in this case), but instead of returning to the loop the program haults. Some times it dies immidiatly, sometimes it starts looping reading from the hard drive. I have checked, all the memory for player* has been created succesfully. Thanks for ANY input for anyone, feel free to help, cause I'm lost on this one ~zix~
Zipster
Zipster
It's very hard to tell without debugging the program myself, but it might be stack corruption. If the return address from the function gets ruined then your program could jump to unpredictable locations.
zix99
zix99
Quote:
Original post by Zipster
It's very hard to tell without debugging the program myself, but it might be stack corruption. If the return address from the function gets ruined then your program could jump to unpredictable locations.


What I dont understand, in that case, is why the program would work fine in Debug mode, and under the release mode just in the IDE.. does this seem fishy to anyone else?

thanks
~zix~

EDIT: After reading another post I've decied to add fluid studio's MMGR, maybe it will catch something, although I'm having a bit trouble getting it to compile.. but thanks for any advice.
zix99
zix99
Well, MMRG found 103 memory leaks, which i had fixed in 15 minutes. The problem no longer exists, so thanks to the other thread!

I highly recommend MMRG for anyone, as publicity for them :), for finding memory leaks in programs.

Thanks for the help.
~zix~

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.