I've got a list
of unique-ptrs
which, upon clearing the list, gives the following error:
Unhandled exception at 0x013EA350 in Last.exe: 0xC0000005: Access violation reading location 0xFEEEFEEE.
This is triggered in the std::list file, when iterating through the elements. The problem is a little unique:
- A
MenuManager
has a list ofunique_ptr<Menu>
objects. - A
Menu
has a list ofunique_ptr<MenuItem>
objects. - The first
Menu
and all of itsMenuItems
destruct perfectly, however this error is triggered during the clearing of the secondMenu
in theMenuManager
's list, with completely independentMenuItems
. It appears as if the secondunique_ptr<Menu>
has become undefined after the destruction of the first, although it was present and non-null at the beginning of theMenuManager
's destruction.
What is causing this? (Not, specifically, where in my code I'm causing this error. I'm wondering what the general cause of this could be)
MenuManager.h
class MenuManager
{
public:
/*MenuManager(list<Menu*> menus)
: m_menus(menus) { SetMenu( menus.front() ); }*/
MenuManager() : m_currentMenu(nullptr) {}
// Get the menu that the manager is pointing to.
Menu* GetCurrentMenu(void) { return m_currentMenu; }
// Set the current menu based on its name.
void SetMenu(string menuName) { SetMenu( GetMenuByName(menuName) ); }
// Add a menu to the list of menus managed by this object.
void AddMenu(Menu* menu);
// Render the current menu.
void RenderMenu(void) { m_currentMenu->Render(); }
private:
list< unique_ptr<Menu> > m_menus; // The list of menus managed by this object
Menu* m_currentMenu; // A pointer to the menu in current use
Menu* GetMenuByName(string menuName);
void SetMenu(Menu* menu); // Set the menu based on the menu argument
};
Menu
is a subclass of another, largely irrelevant class. However, its list is defined as list< unique_ptr<MenuItem> >
. MenuItem
's definition is inconsequential.