Tracing pointers

This is a discussion on Tracing pointers within the Game Programming forums, part of the General Programming Boards category; I have an odd occurance I found while doing some testing in my game today. If I go through and ...

  1. #1
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320

    Tracing pointers

    I have an odd occurance I found while doing some testing in my game today. If I go through and kill the slimes - did this while testing dodge/hit algos - then leave the map and re enter to have the respawn occasionally - not every time and never to all monsters just one - they seems to spawn with 1hp or maybe less than 1hp because one hit will kill them. I think this may be a lingering pointer poiting to a dead monster from the previous load - which should be deallocated upon map change - now I am wondering if anyone can tell me how to track the pointers so I can figure out why it blips like this occasionally.

    I do want to say one more thing I delete the map everytime and reallocate the memory so this should be a fresh load every time.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    To test your hypothesis, set the HP of monsters you just killed to some known magic value.

    Also make sure that as you delete things, specifically set the pointer to NULL.

    Which OS/Compiler are you using?
    VC++ for example has a debug options for memory allocation
    - freed memory is not actually freed, but appended to a free list. Unless you run out of memory, you'll never see this again disguised as another allocation.
    - freed memory is filled with known junk (0xCD IIRC), so you instantly recognise "use after free" issues.
    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.

  3. #3
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Win Vista
    Code::Blocks compiler
    Allegro
    I will try setting the pointers to NULL after the deletes and see if that helps the situation.

    The HPs are set in the map file along with sprites and other attributes so thats not an issue - the checking I mean.


    Now I have an even more intermitant problem - almost like data is getting changed out in the middle of nowhere its really odd has caused crashes on two seperate accounts dealing with different parts of the code. Worse yet I am unable to reproduce these crashes at all - same map same item same code did same things. How do you all deal with errors like this?
    Last edited by ~Kyo~; 04-26-2010 at 11:32 PM. Reason: Another question....

  4. #4
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    I would try using a debugger. Start tracing values etc. Salem had some good ideas...


    Which OS/Compiler are you using?
    VC++ for example has a debug options for memory allocation
    - freed memory is not actually freed, but appended to a free list. Unless you run out of memory, you'll never see this again disguised as another allocation.
    - freed memory is filled with known junk (0xCD IIRC), so you instantly recognise "use after free" issues.
    -- Will you show me how to c++?

  5. #5
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Quote Originally Posted by mramazing View Post
    I would try using a debugger. Start tracing values etc. Salem had some good ideas...
    Debugger fails to start as stated in another post on this forum. Being intermitant makes me think the logic is good just that somehow someway part of the time some error occurs. I know all the files are properly formatted - checked by hand.

    I have only had one occurance of one crash where many tiles loaded then I went over to an object in the game interacted with it checked inventory (object gives an item) had item so all was good exited inventory screen displayed properly but with some tiles displaying transparent then crashing for no reason have not been able to reproduce this error at all.

    Normally a debugger isn't a bad idea, but if you can not recreate the issue - then it becomes a mute point.

    I keep playing with the game here and there still have not seen the same issues I am not sure if it was just one issue one time maybe a memory blip on the computer's side. I did check the memory in this laptop since one stick has a problem staying in the slot both sticks were in their slots. Still dumbfounded on this error as I said before I have not seen it nor has anyone recreated it again. I will post more when I get some more data to post sadly with I think 3 people with .exe files or the code and .exe files this might take a while.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    [quote[
    Debugger fails to start as stated in another post on this forum.
    [/quote]
    Why? This is extremely suspect to me and would indicate you have some problems in your code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers to arrays
    By rakeshkool27 in forum C Programming
    Replies: 1
    Last Post: 01-24-2010, 06:28 AM
  2. pointers to constants and constant pointers
    By homeyg in forum C++ Programming
    Replies: 1
    Last Post: 06-18-2005, 12:02 AM
  3. Arrays, pointers and strings
    By Apropos in forum C++ Programming
    Replies: 12
    Last Post: 03-21-2005, 10:25 PM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM
  5. Pointers to function(function pointers)
    By abhishek_charli in forum C Programming
    Replies: 4
    Last Post: 06-23-2002, 01:24 AM

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