Deque problem with shared_ptr
-
Hey all. I have a
deque<MenuPtr>
andMenuPtr
is typedef ofshared_ptr<Menu>
. Not sure what i am doing wrong but I get the following error message when i rundeque.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
-
Hey all. I have a
deque<MenuPtr>
andMenuPtr
is typedef ofshared_ptr<Menu>
. Not sure what i am doing wrong but I get the following error message when i rundeque.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
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!
-
Hey all. I have a
deque<MenuPtr>
andMenuPtr
is typedef ofshared_ptr<Menu>
. Not sure what i am doing wrong but I get the following error message when i rundeque.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
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
-
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!
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
-
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
Hmm ok. Any idea of why this would happen. Or how did you overcome the problem? Luke