Jump to content
  • Advertisement
Sign in to follow this  
Hermes

Access violation error[Please HELP]

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

Hi here me out: I have a class calledCMove which is used as a node in a single linked list and this class has an implementation of a kill function (see below).Another class CHead inharits the CMove class and also has some new facilities.The first node(the CHead is not supposed to "die" ;the problem is when i try to kill the first CMove node in the list,i get an access violation afterwards.
void CMove::Kill(int i)
{

   if(next)
   {
      if(next->index==i)
      {
         CMove* dead=next;
         next=next->next;
         delete dead;
         dead=NULL;

         return;
      }

      if(next->index<i)
      { 
         next->Kill(i);
         return;
      }

      if(next->index>i)
         return;

   }

  return;
}

I hope i made it clear to you ,i'm in big pain because all the other killings work . Thanks a lot[sad]
Fruny - [‍source] tags, formatting

Share this post


Link to post
Share on other sites
Advertisement
Writing a recursive 'kill' function isn't a good idea. Can you give more details regarding your problem; I can't see what's going wrong here.

That aside, I strongly suggest you redesign your system around a standard C++ container like std::vector or std::list. It spares you from having to debug that kind of things...

Share this post


Link to post
Share on other sites
Without seeing the code of your CHead class this is mostly guesswork, but is it possible that CHead's next pointer isn't updated when the first node is destroyed? If that is the case, then you will get an access violation as CHead treats the recently freed memory as a valid CMove pointer.

Otherwise, try posting the Kill method of your CHead class.

- Neophyte

Share this post


Link to post
Share on other sites
Well i figured out where the problem was ,i was loosing my head somewhere (i mean the CHead[lol])since this wasn't supposed to die when accessing it without any king of protection it threw me an access violation error.
I should have thinked about that.
ThankX !

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!