Hello once again,
I was hoping you might want to explain me why my application crashes on std::vector erase.
So let me introduce you into my code:
I have packet stream. I defined the packet where the informations about object are set.
Then there is class for this object:
Description of CObject:
It has 3 member variables which points to the heap. Two of those variables are optional.
(I will use some random names for those variables, it doesn't really matter)
The CObject has constructor which sets these pointers to zero.
The CObject has copy constructor which:
a) Sets the pointers of destination object to zero
b) Checks the pointers of source object if they are not zero (Because of optionality)
if( ObjectSource.m_chObjectName != 0)
c) Copies rest of the variables.
this->m_nID = ObjectSource.m_nID
The CObject has it's member method which takes buffer of packet as parameter and sets all corresponding variables of the class to the values specified in the buffer. The signature of method is void CObject::SetObjectByPacket(unsigned char * byObjectPacket)
The object destructor:
a) Checks if pointer == 0 and if not delete it
delete  m_chObjectName;
m_chObjectName = 0;
Description of CObjectWrapper
This class is like interface class for CObject
It has one std::vector <cobject> member variable called m_Objects.
It has 2 member methods:
void CObjectWrapper::InsertObjectFromPacket(unsigned char * byDataBuffer)
void CObjectWrapper::DeleteObjectByID( unsigned long ulObjectID )
int nSize = m_Objects.size();
for(int i = 0; i < nSize; i++)
if(m_Objects[i].GetObjectID() == ulObjectID)
So where is the problem:
The application crashes after some time on
while calling destructor of that CObject. The heap pointers of that CObject are something strange but certainly not zero. I could bypass that by using static size for those names and descriptors, but this bugs me so I want to know the answer.
Thank you for you help.