Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Serialization produces memory fault -- even in this TINY class!

__c4.ep__c4.ep Posts: 28Member
[b][red]This message was edited by __c4.ep at 2003-5-20 7:37:21[/red][/b][hr]
Alright, I've tried everything over the last 5 hours, but I just can't get this code to work.

What I want to do is to serialize a class in an SDI app (created with app wizard), which holds a list of another class holding a CString object. Here's the code:

[code]
// header

class COther
{
public:
CString m_str;
};

class CData
{
public:

void Serialize( CArchive& ar )
{
m_list.Serialize( ar );
}

CList m_list;
};
[/code]

Then I instantiate CData in CSerializationDoc and add an object of COther to the list in CSerializationDoc's ctor:

[code]
CSerializationDoc::CSerializationDoc()
{
// TODO: add one-time construction code here
COther obj;
obj.m_str = "Text";
m_data.m_list.AddTail( obj );
}
[/code]

Then I finally have my Serialization func:

[code]
void CSerializationDoc::Serialize(CArchive& ar)
{
m_data.Serialize( ar );
}
[/code]

Well, if I run this app and load a document, I'm getting memory faults when exiting the app. The errors occur in CStringData::Release().
Obviously, the app tries to release a CString which already HAS been released, thus trying to delete data where nothing is anymore.

Does anyone know what the heck is going wrong here?
I have already posted two times on codeguru.com but noone can help me there. Perhaps you can?


«13

Comments

«13
Sign In or Register to comment.