Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#22 Serialization of CPointCloudColoured::TPointColour fails

closed-fixed
J.L. Blanco
5
2009-12-15
2009-12-14
miyamoto musashi
No

The serialization of the input ">>" operator (readFromStream) fails for std::vector<CPointCloudColoured::TPointColour>.

I've been using MRPT to display scan data (using my own sensor driver) into a CDisplayWindow3D and currently need to serialize the scene and communicate it to another program. Generating the output stream with the "<<" operator (writeToStream) works OK, the problem is when reading it.

Consider the following code fragment:
/*---------------------------------*/
mrpt::slam::CColouredPointsMap theMap;
COpenGLScenePtr scene = COpenGLScene::Create()
COpenGLViewportPtr view=scene->getViewport("main");

//we prepare the scene and load some "coloured" points into theMap
//[....]

//then insert theMap into the scene
ptsMap = opengl::CSetOfObjects::Create();
theMap.getAs3DObject(ptsMap);
view->insert( ptsMap );

//and after inserting other funny things into the scene, serialize it into an output file (for this example)
CFileOutputStream(some_file_name) << scene;

/*
Up to here everything works OK, the scene is nicely rendered
*/

//[Some time later, in a different program....]
//We read the serialized scene (particularly the CPointCloudColoured data):
CFileInputStream(some_file_name) >> scene;
//***********************
//CRASH!!!
//***********************
/*---------------------------------*/

The program crashes with the following exception:
---------------------------
terminate called after throwing an instance of 'std::logic_error'
what():

=============== MRPT EXCEPTION =============
mrpt::utils::CStream& mrpt::utils::operator>>(mrpt::utils::CStream&, std::__cxx1998::vector<_Tp, std::allocator<_Tp1> >&) [with T = mrpt::opengl::CPointCloudColoured::TPointColour], line 112:
Error: serialized container std::vector<CPointCloudColoured::TPointColour>'s preambles is wrong: ''
Exception while parsing typed object 'CPointCloudColoured' from stream!

Exception while parsing typed object 'CSetOfObjects' from stream!

Exception while parsing typed object 'COpenGLViewport' from stream!

Exception while parsing typed object 'COpenGLScene' from stream!
---------------------------

heMap.getAs3DObject returns a CPointCloudColoured object which has a vector of TPointColour (m_points) and the serialization of std::vector<CPointCloudColoured::TPointColour> fails, an exception is thrown in $MRPT/include/mrpt/utils/stl_extensions.h, the code is:

CStream& operator >> (CStream& in, CONTAINER<T> &obj) \ { \ obj.clear(); \ string pref,stored_T; \ in >> pref; \ if (pref!=#CONTAINER) THROW_EXCEPTION(format("Error: serialized container %s<%s>'s preambles is wrong: '%s'",#CONTAINER,TTypeName<T>::get().c_str(),pref.c_str() )) \

Now, in the output file the preamble "CPointCloudColoured::TPointColour" exists and is preceded by "std::vector" preamble and some four bytes, and the vector is preceded by "CPointCloudColoured" preamble, so it looks OK. But according to the exception it's reading nothing ('') from the input stream.
An just for the sake of completeness, also tried reading the scene with the SceneViewer3D application with same results (as expected).

Any idea what is the problem here?? Why is it getting empty?
BTW: I'm attaching a scene data file, it might help.

Best Regards

Discussion

  • A sample scene output file, each point cloud (ptsMap in the code) has also a name associated with ptsMap->setName(some-string)

     
    Attachments
  • J.L. Blanco
    J.L. Blanco
    2009-12-15

    Thanks for the very detailed report!

    If I remember it right, this bug was already fixed in the current SVN version. If possible, please try this version:

    http://babel.isa.uma.es/mrpt/index.php/MRPT_SVN_Repository

    until the new release comes out.
    If you try this and it works, please let me know to close this bug file.

    Best regards.

     
  • J.L. Blanco
    J.L. Blanco
    2009-12-15

    • status: open --> open-fixed
     
  • Thanks, using the SVN version did the trick! Effectively this bug is fix on SVN version.

    However I found some bugs in the revision 1346 while compiling and then using it, in the following lines I summarize them and will add a new bug report with a patch to correct them.

    Compilation errors:
    1. src/core/system/os.cpp
    2. samples/rovio_test/test.cpp

    Runtime bugs:
    1. src/core/gui/CDisplayWindow3D.cpp, method CMyGLCanvas_DisplayWindow3D::OnKeyDownCustom
    with the currently commented line: //GetParent()->ProcessEvent(ev); // TODO: Check...
    key events are not processed

     
  • J.L. Blanco
    J.L. Blanco
    2009-12-15

    • status: open-fixed --> closed-fixed