debugging a Boost serialization assertion
-
I'm trying to use Boost serialization in a C++ project, and my code has triggered the assertion on line 103 of this file. That's the line
BOOST_ASSERT(false);
in the bottom-most function in the file. What kinds of things can cause this failure? The context is that I have a class called Board, whose serialize() overload starts by trying to serialize the member
std::arraym_whiteArmy
where Piece is another of my own classes. Trying to serialize m_whiteArmy is what triggers the assert. I've tried putting a breakpoint at the top of Piece's serialize() overload. The assertion triggers before it's reached. I would include a compileable example, but when I've tried writing a toy program to replicate the problem, the toy program has worked. The two most suspicious things I can think of that my attempts at toy programs haven't replicated are that the Board object I'm trying to serialize is a global, and the project is spread over multiple files. Piece is a base class, and m_whiteArmy stores pointers to derived Piece objects, so maybe it matters which file I use
BOOST_CLASS_EXPORT_GUID
to register the derived classes in, and I've chosen the wrong one? Maybe this is all irrelevant - I have no idea where to begin.
-
I'm trying to use Boost serialization in a C++ project, and my code has triggered the assertion on line 103 of this file. That's the line
BOOST_ASSERT(false);
in the bottom-most function in the file. What kinds of things can cause this failure? The context is that I have a class called Board, whose serialize() overload starts by trying to serialize the member
std::arraym_whiteArmy
where Piece is another of my own classes. Trying to serialize m_whiteArmy is what triggers the assert. I've tried putting a breakpoint at the top of Piece's serialize() overload. The assertion triggers before it's reached. I would include a compileable example, but when I've tried writing a toy program to replicate the problem, the toy program has worked. The two most suspicious things I can think of that my attempts at toy programs haven't replicated are that the Board object I'm trying to serialize is a global, and the project is spread over multiple files. Piece is a base class, and m_whiteArmy stores pointers to derived Piece objects, so maybe it matters which file I use
BOOST_CLASS_EXPORT_GUID
to register the derived classes in, and I've chosen the wrong one? Maybe this is all irrelevant - I have no idea where to begin.
Start by having a look at the full code containing the assert statement:
BOOST_ARCHIVE_DECL(const basic_serializer *)
basic_serializer_map::find(
const boost::serialization::extended_type_info & eti
) const {
const basic_serializer_arg bs(eti);
map_type::const_iterator it;
it = m_map.find(& bs);
if(it == m_map.end()){
BOOST_ASSERT(false);
return 0;
}
return *it;
}The assertion is thrown when the specified element can't be found in the container (see map::find - C++ Reference[^] ). Locate where the
find
function is called in your code and check the passed argument. -
Start by having a look at the full code containing the assert statement:
BOOST_ARCHIVE_DECL(const basic_serializer *)
basic_serializer_map::find(
const boost::serialization::extended_type_info & eti
) const {
const basic_serializer_arg bs(eti);
map_type::const_iterator it;
it = m_map.find(& bs);
if(it == m_map.end()){
BOOST_ASSERT(false);
return 0;
}
return *it;
}The assertion is thrown when the specified element can't be found in the container (see map::find - C++ Reference[^] ). Locate where the
find
function is called in your code and check the passed argument.I found that what displayed when I hovered my cursor over the variable eti just before the assert triggered while debugging contained, among other things, the string "rook". That's the string I had associated with the derived Piece class I would expect the first element of m_whiteArmy to point to an element of using BOOST_CLASS_EXPORT_GUID, so I figured there was something wrong with how I did that association. I tried moving my calls of that macro from the top of the Piece cpp file to the top of the main file, and the assertion has gone away. I wish I knew why this is correct and what I'd done before wasn't, but it least it seems to be working now.