Thread: Where to start debugging an exception

  1. #1
    Registered User
    Join Date
    Aug 2009

    Where to start debugging an exception

    I have a d3d program, that if I run it and leave it alone it will render a scene and wait for keyboard input but in a few minutes will come up with an unhandled exception (access violation) calling a particular d3d method. The reason isn't obvious as the program works well otherwise and the method's parameters are not variable.

  2. #2
    Registered User
    Join Date
    Jun 2005
    It's hard to give specific advice, as you haven't really given specific information.

    Presumably your program is doing something while waiting for keyboard input (eg crunching some numbers, rendering some graphics). Somewhere in that process it is probably tromping on some memory in an invalid way (eg dereferencing a NULL, accessing memory through a dangling reference, falling off the end of an array) and that operation is causing your access violation.

    Personally, I would look for any code that is working with an array or a pointer, and check the various operations (preconditions, postconditions, etc) of each operation. If you code is multithreaded, make sure only one thread does rendering [a common gotcha] and that access to all shared resources (i.e. resources used by multiple threads) are synchronised.

    The more timid - but easier to implement - approach is to comment out parts of your code, and see if the problem still occurs. If a problem ceases when you comment out some code, then there is a fair chance that code contains the culprit. The problem with this approach is that it is possible to get false positives and false negatives (and very difficult to catch some more complex things such as two - or more - functions doing something invalid, but the effects of both are needed to trigger your symptoms).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Aug 2009
    The access violation is a reading one. I began looking for an out of range subscript, and found one, also the exception was happening at 3 minutes from run.

    Now it is happening at this line

    i_buffer->Lock(0, 0, (void**)&pVoid, 0);

    6 minutes after run.

  4. #4
    Join Date
    Oct 2007
    Inside my computer
    You may replace all of your native arrays with boost::array for added bonus of range checking.
    As for the above, two questions comes to mind: is pVoid valid and is i_buffer valid (ie not corrupted)?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using swap to make assignment operator exception safe
    By George2 in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2008, 06:32 AM
  2. unexpected exception handler
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 01-10-2008, 05:49 AM
  3. Bjarne's exception safe sample
    By George2 in forum C++ Programming
    Replies: 13
    Last Post: 12-28-2007, 05:38 PM
  4. is such exception handling approach good?
    By George2 in forum C++ Programming
    Replies: 8
    Last Post: 12-27-2007, 08:54 AM
  5. Problem in debugging in Eclipse
    By Bargi in forum Linux Programming
    Replies: 1
    Last Post: 08-21-2007, 09:53 AM