program crashing...some times

Started by
10 comments, last by python_regious 19 years, 7 months ago
Hey my opengl program crashs after the thing that asks you if you want full screen to be on...but it works fine if you run the from the compiler(DevC++)...any ideas on what is making this do that?
Advertisement
Off the top of my head, this usually happens because:

1. You moved the .exe file and it can't find something it needs to run.
2. Memory leak.

Probably the second one.
~~~~~Screaming Statue Software. | OpenGL FontLibWhy does Data talk to the computer? Surely he's Wi-Fi enabled... - phaseburn
oh ok....im not 100% sure what that is...i think i have an idea...but its not very clear can you give me an example?

Edit: im rather new to c++ if you cant tell :D
Quote:Original post by kc_0045
oh ok....im not 100% sure what that is...i think i have an idea...but its not very clear can you give me an example?
Ok, let me try...

Example 1:
You're opening a file as part of your program. In the compiler, your .exe ran just like it's in the main directory.. When you run your .exe in the debug / release directory, it's one folder over, so it can't find it.

Example 2a:
You assume a variable is zero. It is zero in debug(compiler) mode, but not in release mode. i.e.

int foo;

cout << foo;

would produce 0 in the compiler, undefined otherwise.

Example 2b:
In a debug setting, this might produce a valid result, but in a release setting, this would cause an error.

char *foo

cout << foo;


Example 2c:
You indexed something beyond an array. This might work in debug, but not release mode. :/

char foo[10];

foo[99] = bar;

If this doesn't help, produce the source and I'll give it a look. :)





~~~~~Screaming Statue Software. | OpenGL FontLibWhy does Data talk to the computer? Surely he's Wi-Fi enabled... - phaseburn
ok i think i found the problem. its the last one i think, heres what i got im making a grass placement thing...so it makes 500 grass things in a range.
int grass_max=500;GLfloat grass_x[500];GLfloat grass_y[500];


then to draw each one of them i have
int CreateGrass(){    for(int g=0;g<grass_max;g+=1)    {        grass_x[g]=(random()*2.0f)-1.0f;        grass_y[g]=(random()*2.0f)-1.0f;    }  } 

would that make a memory leak?
That shouldn't create a memory leak. g never goes above the max. By the way you can have g++ instead of g+=1.
as a last resort try slapping in a whole bunch of printf's alll through your code, and then run it and see what the last thing to be printed is before the crash. :) pretty rought but it can work quite well
I always find that creating a realtime logfile which your program writes to is very useful for this sort of problem. Generally, you'd write an entry for each section of your code (something like "CGrassDrawer::GrassDraw() started"), this way you can visibly see the last place the code got to in the log before it crashed. Obviously, allow some functionality to start/stop logging with little change to your code.

Another good trick is to throw around asserts() (from <assert.h>) to check whether a variable or function return is as you expected. The best thing about asserts is that they only show up under debug builds and not under release, so you can safely use them a lot throughout your program without having to remove them when it comes to a final compile.
ok thanks for the ideas :D ill try some stuff out and get back to you! :D
When your program crashes, you should get a dialog where you can choose to debug the program. Click that button to open the debugger for the crash. Or you can open your development environment and attach to the program while it's in the crash dialog.

Then, look up the stack for your code that crashes, and examine variables to figure out why it crashes.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement