delete
Lee,
>>
I've encountered a memory deallocation error while I trying to
release CObjList to system. The program runs perfectly if I don't
retrive serialized files. It even runs without errors until I try
to quite the program or to reopen another serialized file.
This is a SDI program. I've spend over a week to debug it, but
simply failed. Could you tell me any possible miscoding that will
cause this problem?
Document Clas
…
int m_nBoardArray[ E9_MAPWIDTH ][ E9_MAPHIGH ];
CObList m_unitList;
…
void CUnit::Serialize( CArchive& ar )
{
if ( ar.IsStoring() ){
ar.Write( &m_nSprite, sizeof( m_nSprite ));
ar.Write( &m_bIsTerrian, sizeof( m_bIsTerrian ));
ar.Write( &m_bSorted, sizeof( m_bSorted ));
ar.Write( &m_unit, sizeof( m_unit ));
}
else{
ar.Read( &m_nSprite, sizeof( m_nSprite ));
ar.Read( &m_bIsTerrian, sizeof( m_bIsTerrian ));
ar.Read( &m_bSorted, sizeof( m_bSorted ));
ar.Read( &m_unit, sizeof( m_unit ));
}
}
<<
The only thing I saw that could be a problem here was that you were
writing out m_unit, an object of a type I don't know. If this is a
C++ class object (especially if it is CObject derived), you will
run into problems just writing it out and reading it in. (Internal
pointers will be invalid.) Instead, you need to call its Serialize
function or use the << and >> operators to store and read it.
Good luck with this.
Tarn Faulkner
Microsoft Developer Support