Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Deque problem with shared_ptr

Deque problem with shared_ptr

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Luke Murray
    wrote on last edited by
    #1

    Hey all. I have a deque<MenuPtr> and MenuPtr is typedef of shared_ptr<Menu>. Not sure what i am doing wrong but I get the following error message when i run deque.clear();

    Unhandled exception at 0x004590e9 in menu.exe: 0xC0000005: Access violation reading location 0xfaaafaa2.

    What is happening in that method? It remove the shared pointers from the list and anything else? Or am I doing something really dumb? Cheers. Luke

    M J 2 Replies Last reply
    0
    • L Luke Murray

      Hey all. I have a deque<MenuPtr> and MenuPtr is typedef of shared_ptr<Menu>. Not sure what i am doing wrong but I get the following error message when i run deque.clear();

      Unhandled exception at 0x004590e9 in menu.exe: 0xC0000005: Access violation reading location 0xfaaafaa2.

      What is happening in that method? It remove the shared pointers from the list and anything else? Or am I doing something really dumb? Cheers. Luke

      M Offline
      M Offline
      M Mehrdad M
      wrote on last edited by
      #2

      i had this problem before. it is because of size of Entities you En/Deque in Queue. it is not the same value that queue thinks! for example you Enque 5 Byte Entities But Que try to dequeue 10 Bytes Entities.;P M.Mehrdad.M

      L 1 Reply Last reply
      0
      • L Luke Murray

        Hey all. I have a deque<MenuPtr> and MenuPtr is typedef of shared_ptr<Menu>. Not sure what i am doing wrong but I get the following error message when i run deque.clear();

        Unhandled exception at 0x004590e9 in menu.exe: 0xC0000005: Access violation reading location 0xfaaafaa2.

        What is happening in that method? It remove the shared pointers from the list and anything else? Or am I doing something really dumb? Cheers. Luke

        J Offline
        J Offline
        Jack Puppy
        wrote on last edited by
        #3

        You'd have to post your code, I can't tell much from what you've posted, other than it's a bad pointer exception. I just whipped this and it worked fine.

        // testsharedptr.cpp : Defines the entry point for the console application.
        //

        #include "stdafx.h"
        #include <boost/shared_ptr.hpp>
        #include <deque>
        #include <crtdbg.h>

        class Menu
        {
        int m_x;
        int m_y;

        public:
        Menu(int x, int y) : m_x(x), m_y(y)
        {}
        Menu(const Menu& menu)
        {*this = menu;}
        virtual ~Menu()
        {}
        Menu& operator=(const Menu& menu)
        {
        if (this != &menu)
        {
        m_x = menu.m_x;
        }
        return (*this);
        }
        };

        typedef boost::shared_ptr<Menu> MenuPtr;

        int _tmain(int argc, _TCHAR* argv[])
        {
        _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

        Menu\* one = new Menu(1,2);
        Menu\* two = new Menu(3,4);
        
        std::deque<MenuPtr > myDeque;
        myDeque.push\_front(MenuPtr(one));
        myDeque.push\_back(MenuPtr(two));
        
        return 0;
        

        }

        :suss: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!

        L 1 Reply Last reply
        0
        • J Jack Puppy

          You'd have to post your code, I can't tell much from what you've posted, other than it's a bad pointer exception. I just whipped this and it worked fine.

          // testsharedptr.cpp : Defines the entry point for the console application.
          //

          #include "stdafx.h"
          #include <boost/shared_ptr.hpp>
          #include <deque>
          #include <crtdbg.h>

          class Menu
          {
          int m_x;
          int m_y;

          public:
          Menu(int x, int y) : m_x(x), m_y(y)
          {}
          Menu(const Menu& menu)
          {*this = menu;}
          virtual ~Menu()
          {}
          Menu& operator=(const Menu& menu)
          {
          if (this != &menu)
          {
          m_x = menu.m_x;
          }
          return (*this);
          }
          };

          typedef boost::shared_ptr<Menu> MenuPtr;

          int _tmain(int argc, _TCHAR* argv[])
          {
          _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

          Menu\* one = new Menu(1,2);
          Menu\* two = new Menu(3,4);
          
          std::deque<MenuPtr > myDeque;
          myDeque.push\_front(MenuPtr(one));
          myDeque.push\_back(MenuPtr(two));
          
          return 0;
          

          }

          :suss: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!

          L Offline
          L Offline
          Luke Murray
          wrote on last edited by
          #4

          Sorry don't have the code on me right now. I'll reply again later when at home. But i'll try to get it across now. I have a Menu class that contains a deque of other MenuPtr's as you can add Menu object to Menu objects. One way is vis Menu::add(MenuPtr& menu); or Menu::add(Menu* menu); So in another class I have a Menu object which I add other Menu object to, etc. I have been messing around with both, but when I use the Menu* one I never delete the pointer I created so that should cause a problem. So I get the error when I do Menu::clear which clears the list of child menus. or when I quit the program as in the deconstrutor it also call clear(). Hope this makes it clear. I'll be back home later and look at the code again. Thanks Luke

          1 Reply Last reply
          0
          • M M Mehrdad M

            i had this problem before. it is because of size of Entities you En/Deque in Queue. it is not the same value that queue thinks! for example you Enque 5 Byte Entities But Que try to dequeue 10 Bytes Entities.;P M.Mehrdad.M

            L Offline
            L Offline
            Luke Murray
            wrote on last edited by
            #5

            Hmm ok. Any idea of why this would happen. Or how did you overcome the problem? Luke

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups