EventManager and shared_ptr

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • EventManager and shared_ptr

      I'm sure I'm doing something wrong but I'm relatively new to boost's shared_ptr and I saw some issues when using the EventManager from the book.

      If I created dynamic memory for a class that implements the IEventListener interface. When I subscribe to any event using the pointer to that object that was created I can't clean up the memory myself at game end without getting an error. Seems boost cleans up the memory for that object for me.

      For example:
      EventListenerPtr Listener( m_pGameManager );
      EventManager::Instance()->RegisterListener( Listener, EventType(PlayActionBegin::s_strName));

      Now m_pGameManager was created by me earlier. If I call delete m_pGameManager then I get an exception. If I don't its destructor is called when the EventManager goes away.

      Any ideas what I may be doing wrong?

      EDIT - Ok I did some web checking on boost::shared_ptr and found a codeproject writeup on using them correctly. I need to internalize it more, though. Looks like the .get() method allows me to pass the native type pointer to functions. I need to pass CGameManager* around in some places.


      Steve
      Steve Jones

      The post was edited 1 time, last by smjones ().

    • RE: EventManager and shared_ptr

      Glad you were able to figure out what was wrong. Google is definitely your friend for finding solutions to weird issues.

      -Rez
    • RE: EventManager and shared_ptr

      Thanks rezination.
      Yeah, I don't like to just ask questions without thoroughly researching for possible answers myself. Google is one of the first places I go.

      I'm going to expose my age a little here, but there was a time in my career when there was no google or any other searching capability as easy as it is today. We had to do lots of phone calls or lots of walking over to the large, hardbound reference material to find answers. Or we just didn't get answers and had to wing it. :)

      Steve
      Steve Jones
    • RE: EventManager and shared_ptr

      Well - I remember when there were no telephones - I had to get on my horse and ride into town to the local programming guru. He took his payment in whiskey, which was fine because I generally had plenty of that.

      Ok I'm kidding about the horse.
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • RE: EventManager and shared_ptr

      I got stiffed on a contract when a company was shutting down. I left the place with a monitor and some scotch and whiskey from the so called executive liquor cabinet. I finished that whiskey long ago. you aren't hiring are you Mr. Mike?