Hi, today, I have add the serialization feature to my own class, and I found that some times, my program crash, narrow down the crash issue, I found that the SerializableObject can not be used in std::vector, here is an example (modified code from SimpleListSample sample code)
intmain(intargc,char**argv){//createinstanceofXMLserializerwxXmlSerializerSerializer;std::vector<SerializableObject>v;//first,createsetofserializableclassobjectsandaddthemtotheserializerfor(inti=0;i<5;i++){//Addallnewclassobjectstotheserializer'sroot(pointertoparentobjectisNULL)//sotheinstanceswillbearrangedintoalist.Notethateachserializableobject//couldbeassignedasachildtoanotheronesotheobjectscouldbearrangedintoatree//structureaswell.SerializableObject*p=newSerializableObject();Serializer<<p;v.push_back(*p);//alsomemberfunctionofwxXmlSerializercouldbeusedforthistaskasfollows://Serializer.AddItem((xsSerializable*)NULL,newSerializableObject());}//storetheserializer's content to an XML file Serializer.SerializeToXml( wxT("data.xml") ); // clear the serializer'scontentSerializer.RemoveAll();for(inti=0;i<5;i++){v.erase(v.begin());}
Note, in my code, I use a vector to hold SerializableObject, the code above always crash on the second run of the for loop, the crash stack looks below:
[debug]> bt 30
[debug]#0 0x6734ad19 in wxmsw28u_xs!_ZN18wxPropertyListNode10DeleteDataEv () from D:\new_opencv_wxWidgets\wxxs-code-112-trunk\lib\gcc_dll\wxmsw28u_xs.dll
[debug]#1 0x627305d7 in wxListBase::DoDeleteNode(wxNodeBase*) () from E:\code\wx-mingw-build-481-dw2\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
[debug]#2 0x6273082a in wxListBase::Clear() () from E:\code\wx-mingw-build-481-dw2\wxWidgets-2.8.12\lib\gcc_dll\wxmsw28u_gcc_custom.dll
[debug]#3 0x6734ae46 in wxmsw28u_xs!_ZN14xsSerializableD2Ev () from D:\new_opencv_wxWidgets\wxxs-code-112-trunk\lib\gcc_dll\wxmsw28u_xs.dll
[debug]#4 0x00403e8b in wxString::~wxString (this=0xb4e3f0, __in_chrg=<optimized out>) at E:\code\wx-mingw-build-481-dw2\wxWidgets-2.8.12\include\wx\string.h:659
[debug]#5 0x00403cc4 in SerializableObject::~SerializableObject (this=0xb4e398, __in_chrg=<optimized out>) at D:\new_opencv_wxWidgets\wxxs-code-112-trunk\samples\Sample5\main.cpp:37
[debug]#6 0x00403f0c in __gnu_cxx::new_allocator<SerializableObject>::destroy (this=0x22fe78, __p=0xb4e398) at d:\mingw-builds\i686-4.8.2-release-posix-dwarf-rt_v3-rev0\mingw32\lib\gcc\i686-w64-mingw32\4.8.2\include\c++\ext\new_allocator.h:133
[debug]#7 0x00403fcc in __gnu_cxx::__alloc_traits<std::allocator<SerializableObject> >::destroy (__a=..., __p=0xb4e398) at d:\mingw-builds\i686-4.8.2-release-posix-dwarf-rt_v3-rev0\mingw32\lib\gcc\i686-w64-mingw32\4.8.2\include\c++\ext\alloc_traits.h:219
[debug]#8 0x00404a57 in std::vector<SerializableObject, std::allocator<SerializableObject> >::erase (this=0x22fe78, __position=...) at d:\mingw-builds\i686-4.8.2-release-posix-dwarf-rt_v3-rev0\mingw32\lib\gcc\i686-w64-mingw32\4.8.2\include\c++\bits\vector.tcc:140
[debug]#9 0x00401b1f in main (argc=1, argv=0x3e29b8) at D:\new_opencv_wxWidgets\wxxs-code-112-trunk\samples\Sample5\main.cpp:108
You see, when I delete an SerializableObject in the vector, it finally call some code in wxXmlSerializer, which cause the crash.
Any ideas to fix this crash issue?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You cannot delete the objects managed by serializer class after invocation of RemoveAll() method manually - the objects were already deleted by the serializer. BTW, why did you use std::vector as a storage for serialized objects? wxXmlSerializer class itself is a persistent storage with rich API for handling of stored objects. IMHO you don't need any other container class to work with stored objects.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, today, I have add the serialization feature to my own class, and I found that some times, my program crash, narrow down the crash issue, I found that the SerializableObject can not be used in std::vector, here is an example (modified code from SimpleListSample sample code)
Note, in my code, I use a vector to hold SerializableObject, the code above always crash on the second run of the for loop, the crash stack looks below:
You see, when I delete an SerializableObject in the vector, it finally call some code in wxXmlSerializer, which cause the crash.
Any ideas to fix this crash issue?
Thanks.
You cannot delete the objects managed by serializer class after invocation of RemoveAll() method manually - the objects were already deleted by the serializer. BTW, why did you use std::vector as a storage for serialized objects? wxXmlSerializer class itself is a persistent storage with rich API for handling of stored objects. IMHO you don't need any other container class to work with stored objects.