And here i am... again -_-, hope its ok with you, because this is the only forum i can find with a quick and good answer.
Here is the situation: inside a thread i'm creating a vector<myclass>. myclass is contains some members and functions, non of them are really important. the vector can get a size over 2000, but here is the hitch. for some or other reason, i'm using a loop witch reads every single member of the vector, and manipulates the data. But at some unpredictable moment, the program just crashes. even my exception handler cant catch the error. when the debugger kicks in, i see that he tried to acces a member of the vector. and the pointer was valid. however, every member is the class was gone. all bad pointers and corrupted data. its weird, because there are no other threads accesing that data. does anyone know what's going on here...

Vector data corrputed
Cringing Dragon
Servers is a simple structure with only some data.
ENTER and LEAVE are 2 macro's witch identify critical sections for tread save use.
The error can occour at any random time, at any random place where i call Servers
while(!Servers.empty()){
Sleep(5);
time(&start);
if (Servers.size()>10000){
MisScanned++;
static int counter;
if (++counter>2){
counter=0;
}
throw(new ServerException("Unknown error ocoured", ID));
}
if (RequestServerInfo(&Servers.front())!=0){
MisScanned++;
}
else{
if (Servers.size()>10000)
throw(new ServerException("Unknown error ocoured", ID));
else{
if (DealWithServerInfo(&Servers.front())!=0){
MisScanned++;
}
else{
if (Servers.size()>10000)
throw(new ServerException("Unknown error ocoured", ID));
else{
ENTER(m_cs);
NDServer *Temp = &this->GetFrontOfServers();
TargetList->push(*Temp);
LEAVE(m_cs);
}
Scanned++;
}
}
}
if (Servers.front().Game!=NULL){
Servers.pop();
BRiley
GetFrontOfServers is a function withc tries to get the front of the servers vector. but as i told. the error can occour at any moment. so if the front element is corrupted, it returns a new clean useless instance. just so the application wont crash. i know its ugly, but well. for now, i dont know another way, and i dont know whats the reason behind this error :)
NDServer &GetFrontOfServers(){
if (Servers.front().ID==0){NDServer temp;
temp.ID = GLOBAL;
return temp;}
return Servers.front();}
sunnymax2002
Dennis M.
First, initialized variables. Behaviour is undefined because of this:
static int counter;
if (++counter>2){
counter=0;
}
Set it to 0:
static int counter = 0;
Second, isn't this
NDServer *Temp = &this->GetFrontOfServers();
TargetList->push(*Temp);
the same as
TargetList->push(this->GetFrontOfServers());
Third, where exactly does it crash in this code snippet
Ronn
no, not growing, but shrinking... after each data manipulation is done, i copy the member to another vector in another thread and pops the member of the vector.
Gravy
Mike Mathis
vector<myclass *>
Kuphryn