Archived

This topic is now archived and is closed to further replies.

Mulligan

Need some clever error checking

Recommended Posts

There is a function that I call, which has a tendency every few calls to never return and lock my program up. For instance: void SomeFunction() { ThisSometimesLocksUp(); } What I need is someway to detect wether or not it has locked up, probably via a timer of some sort. The only method I can think of to detect it is by creating a thread that only calls ThisSometimesLocksUp() and terminating the thread if a certain amount of time goes by and it''s still active. But theres got to be a better way, is there?

Share this post


Link to post
Share on other sites
Not to sound rude, but you really should find out why the function is locking up sometimes and fix the problem. This ''bandaid'' solution is bad programming and will likely lead to problems down the road. Often times, problems in one function have a strange way of effecting the rest of the program.

Share this post


Link to post
Share on other sites
you know, it''s computationally impossible to detect lock-ups explicitly (google "halting problem"). if you can debug your code to the point where you can throw an exception when it would normally halt, or if you''re willing to loose some cycles to a timer mechanism (which is an acceptable solution only if you have some very solid upper bounds for time requirements).

Another thought is if you thread it and make it perform ''reports'' to the main thread of your program, then as soon as it stops reporting, you can kill it. That is assuming that you can assuredly make sure it won''t report when it has halted.

George D. Filiotis

I am a signature virus. Please add me to your signature so that I may multiply.

Share this post


Link to post
Share on other sites
Create a function:
AddErrorLog(char *Message)
{
// open a file, log the message, close it.
}

Now every line, or every few lines, strategically call AddErrorLog:

Example:

void YourFunctionThatLocksUp()
{
AddErrorLog("Beginning lockup function...");
//init vars
AddErrorLog("Vars Init.");
// Do stuff
// Do Stuff
AddErrorLog("We made it here...");
}

You get the idea. Then even if your whole system freezes, you still have an error log of where it got to, then check the code for the line it would have locked up on.

Share this post


Link to post
Share on other sites
If you''re going to log to a file, make sure you flush the file after each write (otherwise when you crash, you''ll lose the last few messages, which obviously doesn''t help you find the source of the problem).

If you''re running on Win32 with MSVC, I''d use OutputDebugString() and run your app in Debug mode. Then you look in the ''Output'' panel to see the messages once the app has locked (and you''ve presumably killed it).

assert() is also your friend. Look it up.

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.

Share this post


Link to post
Share on other sites
If your program just locks up, why not break it in the debugger and see why?

If you''re using threads, and you really don''t feel like fixing your problem, you could always use a ''heartbeat'' to detect bad threads.

This works by having a process which simply recieves messages from other threads. Each of those threads should send out a message to this listener every n-milliseconds. If the listening thread doesn''t get anything from a particular thread after a set interval, it kills the thread.

I have to agree with everyone else though: you should really try and find the source of your problem. You should be able to use the debugger to track down the problem.

Cheers,
Will

Share this post


Link to post
Share on other sites
The function which locks up is the OpenGL function . If you know of a reason that it would be locking up, please do tell. I've asked before and no one seems to come up with an answer that works. The main response I get when I ask that is that I've probably not shut opengl down correctly, which i have (i assure you). I figured out which function it was a little while ago, and if i remember correctly, its either
wglCreateContext( m_hDC );
or
wglMakeCurrent( m_hDC, m_hRC );

I made a macro a while back that did something similar to what I need, it worked like this:

void foo
{
TIME_BOMB_THREAD( FailsSometimes(), 1000 )
}

which runs the function FailsSometimes() for 1000 ms in its own thread and kills the thread if it hasnt returned. Probably what I'll end up doing.

[edited by - Mulligan on April 29, 2003 7:57:55 PM]

Share this post


Link to post
Share on other sites
To me it sounds like you really need to debug your program better and tell us exactly WHICH function fails. Not "either or". Also being that it is a Open GL function it could be something being added to the screen / world that is invalid causing it to fail. It could be mkany things. You need to debug better all activity, in all parts of your app that occur prior to the lockup.

It could even be a driver / video card problem. Maybe try updating them.

Share this post


Link to post
Share on other sites
I know about debugging code. I dont want help with debugging or opengl, and i evel left out the fact that it was an opengl function in my origional post. Just want to know of different ways of detecting lockups. I think, however, that its my computer thats the problem.

[edited by - Mulligan on April 30, 2003 6:04:33 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Village Specialton
Are you using MSVS? .NEt has reported errors with the ANSI standard. For more information, get the May 2003 issue of Microsoft Development Journal.

Scott


Humm, ill check that out, thanks.

Share this post


Link to post
Share on other sites
What''s wrong with try/catch statements?

Please note that I haven''t read through all posts.



- Rob Loach
Current Project: Upgrade to .NET and DirectX 9

"Do or do not. There is no try."
- Yoda

Share this post


Link to post
Share on other sites
quote:
Original post by Symphonic
you know, it''s computationally impossible to detect lock-ups explicitly (google "halting problem").


SoftICE?

Not the easiest of tools (and very pricy!), but pretty good for breaking out of just about everything.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Rob Loach
What''s wrong with try/catch statements?

Please note that I haven''t read through all posts.


I actually think vanilla ice cream tastes better than chocolate.

Please note that I haven''t read your post.

Share this post


Link to post
Share on other sites