![]() |
|
Question about std::list and tidying up |
DanielH
Member #934
January 2001
![]() |
I was using my own list class and decided to switch it to std::list. Two classes use it. UndoList: For some reason I am getting a break at the tidying up of ThemeList. Quote: Unhandled exception at 0x0041e062 in sudoku.exe: 0xC0000005: Access violation reading location 0x00000001.
sudoku.exe!std::list<ThemeInfo *,std::allocator<ThemeInfo *> >::clear() Line 612 + 0xf C++ // in game.cpp ThemeList themeList;
// in themelist.cpp ThemeList::ThemeList() { this->screenShot = NULL; this->count = 0; this->place = 0; this->current = 0; this->over = -1; } ThemeList::~ThemeList() { } // line 30 This happens when even when I don't use themeList in the game. themeList only gets used when I am changing themes. [EDIT] What could this be? Im using MSVC7. |
CGamesPlay
Member #2,559
July 2002
![]() |
You are deleteing a pointer that points to 0x00000001, which is invalid... -- Ryan Patterson - <http://cgamesplay.com/> |
ImLeftFooted
Member #3,935
October 2003
![]() |
Set breakpoints at all your ctors and dtors. Namely ThemeList. See how many times the dtor is called and from where. Does the dtor get called more often then the ctor? Other then that advice, theres not much I can figure out about what you're doing. Other then making some type of sudoku game. Try pasting your ThemeList and making the simpliest test case possible that shows the problem you're having (and obviously paste that too). |
ReyBrujo
Moderator
January 2001
![]() |
You need to use std::list<ThemeInfo*> stack;. Can you post the code of the constructor and destructor, as well as members of ThemeInfo? -- |
CGamesPlay
Member #2,559
July 2002
![]() |
Okay, the first sentence in Rey's post isn't true. You can use lists of objects just fine. -- Ryan Patterson - <http://cgamesplay.com/> |
DanielH
Member #934
January 2001
![]() |
I placed breakpoints in ctor, dtor, and each member. ctor was getting called in the beginning of the program as ThemeList is a global. dtor was getting called at the end of the program. No members were getting called and I was still getting the same break. I removed the breakpoints ant removed stack as a member of ThemeList and added it at the top of ThemeList's source. I am having a hard time trying to duplicate the same response. I am getting no break's. Here is the header and source, the commented out parts are what it was.
|
ImLeftFooted
Member #3,935
October 2003
![]() |
With this code for ( int i = 0; i < 10; it++, i++ ) { if ( it == themeStack.end() ) { break; } You did good checking if it is invalid, but with two other loops you forgot to :x. std::list<ThemeInfo>::iterator it = themeStack.begin(); for ( int i = 0; i < this->place; i++ ) { it++; } Never assume an iterator can be incremented and still valid |
DanielH
Member #934
January 2001
![]() |
this->place is always <= to themeStack.size(); |
|