variables changing erratically.

This is a discussion on variables changing erratically. within the C++ Programming forums, part of the General Programming Boards category; At strange times variables within a vector I've made will change. Some examples of "strange times" are returning true from ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    70

    Question variables changing erratically.

    At strange times variables within a vector I've made will change. Some examples of "strange times" are returning true from a function, and allocating things that have nothing to do with anything, for an example you can look at these screen shots taken during debugging.

    http://img294.imageshack.us/img294/3061/captureec8.jpg
    http://img214.imageshack.us/img214/972/capture2bq6.jpg

    My question is if anybody has any idea why or how this would happen, because I don't. My project has no warnings up until level3 at which point a whole bunch of headers I include put out deprecated function warnings.

    Any ideas will help, because as I have said, I don't have any. I can give more information on request.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Can you point out what we should be looking at?

    Sometimes debug displays change because not all values shown in the debugger are valid and being used by the vector (or whatever object). Does your vector have bad data if you actually access it through code?

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    70
    The data is screwed up if I try to access it, and causes crashes. I was trying to find out where it got screwed up and I can't seem to find out because it changes every couple lines seemingly randomly (though consistently between runs). And it gets changed to completely invalid data.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    My guess would be that the BlobManager instance is messed up or you've corrupted the heap somehow. Are you using new/delete in your code? Perhaps deleting something you shouldn't be deleting?

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    So what does
    new int;
    do, apart from waste some memory?

    > My project has no warnings up until level3 at which point a whole bunch of headers I include put out deprecated function warnings.
    Such as?
    You can selectively turn off warnings you know.

    Besides, no warnings doesn't mean you're free to stop thinking about issues. Plenty of valid programs will pass every diagnostic you could ever apply, but will quite happily crash.

    Some debuggers enable you to access the hardware breakpoint registers. Use these to trap writes to memory locations which you think should not be changed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    70
    So what does
    new int;
    do, apart from waste some memory?
    It shouldn't do anything else, but the debugger makes it look like it's changing the values. I'm just using it to eliminate variables, I used to allocate another object there and I wanted to make sure it wasn't something wrong with that.

    Besides, no warnings doesn't mean you're free to stop thinking about issues. Plenty of valid programs will pass every diagnostic you could ever apply, but will quite happily crash.
    Yeah, I just figured I would throw that in.

    Some debuggers enable you to access the hardware breakpoint registers. Use these to trap writes to memory locations which you think should not be changed.
    I'll look into that, it should help.

    Perhaps deleting something you shouldn't be deleting?
    That seems to be the most likely, then the new int could be put into it's place. I use new and delete every once and a while, I'll double check all the places I use it.

    I think I've got a place to start from between the hardware breakpoint business, and checking my memory management. I'll let you guys know how that goes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  2. Remotely Creating Variables
    By Rajin in forum C++ Programming
    Replies: 1
    Last Post: 04-26-2005, 11:20 PM
  3. Problem with changing variables :pointers, functions
    By SyCo1234 in forum C Programming
    Replies: 16
    Last Post: 04-03-2005, 07:49 PM
  4. Declaring an variable number of variables
    By Decrypt in forum C++ Programming
    Replies: 8
    Last Post: 02-27-2005, 03:46 PM
  5. functions to return 2 variables?
    By tim in forum C Programming
    Replies: 5
    Last Post: 02-18-2002, 01:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21