Skip to main content
GameDev.net gamedev.net
🔒 Locked

Strange Behavior

Started by jimboid Sep 13, 2010 at 11:43 AM 8 replies 1.1k views
Original Post
jimboid
jimboid
Hi guys,

Ive been trying to find this problem that I'm seeing with a program that I've been working on for a while now. I'm not sure what I am doing wrong with this so please bare with me. Basically in my main program I have a set of geometries in display lists that I call at given positions in the scene, this works fine for a while but after a certain amount of time the scene goes blank (black screen) with only a single pixel lit.

I got hold of one of nehe's tutorial codes to see if it was my compiler or opengl that had issues but they are fine, so I decided to paste my display code into one of those tutorial codes only replacing the display lists for GL_Points and then a simple for loop to draw a small block on the screen. After about 13-14 minutes of runtime it completely disappears apart from what seems to be a random lit pixel.

Here is the code from the simplified display function, i literally pasted this into one of nehe's (i used tut 25) in place of the original function to reproduce the error.

void DrawGLScene(GLvoid)								{	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		glLoadIdentity();										glTranslatef(cx,cy,cz);									glRotatef(xrot,1,0,0);									glRotatef(yrot,0,1,0);									glRotatef(zrot,0,0,1);									// Problem with this i think	GLfloat offsetx=0.0f,offsety=0.0f,offsetz=0.0f;	GLfloat tx,ty,tz;	int i,j;			for(i=0;i<101;i++){	for(j=0;j<101;j++){	tx=float(i),tz=float(j),ty=1.0f;	glTranslatef((tx-offsetx)*0.00905f,(tz-offsetz)*0.01590f,(ty-offsety)*0.00760f);		glBegin(GL_POINTS);		glColor3f(1.0f,1.0f,1.0f); 		glVertex3f(0.0f, 0.0f, 0.0f);		glEnd();	glTranslatef((-tx+offsetx)*0.00905f,(-tz+offsetz)*0.01590f,(-ty+offsety)*0.00760f);	}}	//end problem area}


Sorry if the code is a bit scrappy, I rushed it when I did that as a test. I'm at a total loss about this, been trying on and off for 3 weeks to fix it so any help would be greatly appreciated.
karwosts
karwosts
Place a call to glGetError in your loop and break if it returns nonzero. If it runs for that long and then breaks perhaps you are leaking resources somewhere. See if it triggers at all before or after you lose your scene. Nothing in your code currently indicates a problem to me.

(by the way it is "bear with" not "bare with")
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
blubberbert
blubberbert
im just guessing here but...
maybe you should place a
glMatrixMode(GL_MODELVIEW);

before your glLoadIdentity
because it might be that somewhere, sometime the projection matrix is modified and the matrixmode isnt switched back
------------------------------
Join the revolution and get a free donut!
jimboid
jimboid
@ Karwosts, thankyou for your reply. I should have mentioned that I had tried a call to glGetError in my real code loop, but it didn't ever trigger with anything. I once got a stack overflow but that was being caused by a large static array which I then altered to dynamic and fixed the issue.

"(by the way it is "bear with" not "bare with")" Sorry about that.

@ bubblerbert, Thankyou for your suggestion it seemed to do the trick in the test function I posted earlier. I'm currently running it in the real code now to see if it works there too, I would never have thought of that. As for why though I'm still confused how that managed to not get set or become unset, I will try to look deeper into my code to see what could cause that since the Nehe code doesnt have to call that in the display function and those tutorials all work. It Just seems strange that in this case it needed that extra call.
jimboid
jimboid
Ok after a lot more testing the inclusion of glMatrixMode(GL_MODELVIEW); didn't work, I must have just been lucky and it ran better that night. I also tried further calls to glGetError which strangely came up with nothing again. I used a profiler to see what happens in the opengl pipeline when the screen goes blank, and it shows that there are still the same number of GL commands being issued after the screen goes blank as before. One other little thing I have noticed is when I click on the close button on the window as the window closes for a split second the scene reappears as the window is destroyed.

Any more ideas as to what might cause this? I'm totally out of ideas now, one more thing is I initialised all of the variables used in the simple example above incase it was that but that didn't work either.
blubberbert
blubberbert
could you maybe post some of your window set up code?
because i think the problem might be there...
also you should probably check some forums for your graphics hardware if there is any known bug that could cause this.
other than that you should maybe write a basic program (triangle or similar, you could check one of the first NeHe tutorials :D) and check if it behaves the same.
------------------------------
Join the revolution and get a free donut!
jimboid
jimboid
If I get one of the Nehe tutorials and compile it in the same project environment as the problem code, the nehe ones compile and run for hours without issues.

The window code in this case can be considered to be any of the Nehe tutorials/base since I'm testing the code I posted in my first post in the basecode before I try to tackle my big program. I'm just trying to keep all of the variables to a minimum since my other program is quite large. I dont think it is anything wrong with the windowing because the nehe ones work fine, but if I replace the display function in say the nehe base with the one I originally posted above then it does this blank screen thing.

You might be right about there being an issue with my graphics card, ive read a lot about ATI and problems but I always assume I have done something stupid before I blame the card/drivers. I don't have access to any nvidia machines, and I can't get access to any other ATI machines until later so I will have to wait to test it on other systems.

This is the current display code I'm using, I have tried initialising all the variables but still disappears in less than 20 mins of run time

void DrawGLScene(GLvoid)							{	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		glLoadIdentity();	glTranslatef(0.0f,0.0f,-30.0f);	GLfloat offsetx=0.0f,offsety=0.0f,offsetz=0.0f;	GLfloat tx=0.0f,ty=0.0f,tz=0.0f;	int i=0,j=0;			for(i=-50;i<51;i++){	for(j=-50;j<51;j++){	tx=float(i),ty=float(j),tz=1.0f;	glTranslatef(tx,ty,tz);		glBegin(GL_POINTS);		glColor3f(1.0f,1.0f,1.0f); 		glVertex3f(1.0f, 1.0f, 1.0f);		glEnd();	glTranslatef(-tx,-ty,-tz);	}}}
21st Century Moose
21st Century Moose
You appear to be not doing a SwapBuffers at the end of your draw function. I know that the Nehe tut has it elsewhere, but you should probably double-check that it is being called.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
jimboid
jimboid
In the nehe code the SwapBuffers is called right after the DrawGLScene(), I have a similar sequence of function calls because I used the nehe tutorials to learn some OpenGL. As I mentioned before if the DrawGLScene I posted above is placed into say the nehe base code in place of the DrawGLScene then it produces the strange behavoir that I'm seeing. I'm going to try it on a different machine later tonight to see if it is just my machine, I'll post back later with an update.
jimboid
jimboid
Ok I have it running on a different machine, it has a more powerful ATI card and it seems to be running fine. Its been running so far for 45 mins so I guess it is my machine that has the issue. Sorry to waste your time guys and thankyou for your help.

Topic Locked

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

Sign in to reply to this topic.