Sign in to follow this  

program crashing...some times

This topic is 4861 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

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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. :)





Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
You can also sprinkle try and catch blocks through your code, with the catch block sending you a friendly message as to its location. I used this the other day to find a completely random array overrun that had been lying in some of the code I share between projects for months.

Share this post


Link to post
Share on other sites

This topic is 4861 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this