Monday, October 25, 2010

New problems to solve...

Today I tried to program some "CreateNew" functions for my classes/structs.
The idea behind that was that I wanted to add newly created objects to an array so they get processed automaticly.

The code looks like this (in this case the timer class):

Timer *CreateNewTimer() {
Timer *pRet = new Timer();
pRet->EraseMe = false;
//Some more initializes
AllTimers.push_front(pRet);
return pRet;
}


In the main function there's a function "CheckAllTimers" which looks like this:

for(auto i = AllTimers.begin();i != AllTimers.end();i++) {
if(!(*i)->EraseMe)
UpdateTimer((*i));
else {
delete (*i);
i = AllTimers.erase(i);
}
}


But somehow I get an error when the timer gets erased from the array (in this case a list)...I tried to fix it for 2 hours...(I used to use vectors and hoped that the error disappears if I switch to lists...But that didn't do it.). I'm pretty damn sure that it has something to do with

i = AllTimers.erase(i);

and I'm also pretty damn sure that something like

if(i != AllTimers.end())

will fix the error but I'm too tired right now to invest more time on trying to fix this error.

No comments:

Post a Comment