Boost logo

Boost Users :

Subject: [Boost-users] Android: segfault while writing to archive during Serialization
From: wespaugh (wespaugh_at_[hidden])
Date: 2013-02-19 20:48:13


Greetings!

New to discussion, apologies in advance for any inadvertent misuse of
terminology / standards. (also, I tried e-mailing this post directly last
night, but it doesn't appear to have shown up, yet. double-apologies if
double-post).

I'm trying to port my project, which involves some serialization code, to
Android. I followed instructions to build boost 1.49 found here:

https://github.com/MysticTreeGames/Boost-for-Android

and can successfully compile my application using crystax NDK r7 (gcc 4.5.3)
, and link it to the Serialization library.

Unfortunately! When my application calls the serialization code to send my
object to the archive, it crashes. I've reduced my actual code to try and
isolate the crash in a way I can post here.

    std::ofstream outStream(MAP_SAVE_FILE, std::ios_base::binary);

    boost::archive::text_oarchive outputArchive(outStream, 1);

    Classroom *c = new Classroom();

    CCLog("Outputting archive");
    // outputArchive << mapInstance;
    outputArchive << c;

The crash occurs at outputArchive << c; "Fatal signal 11 (SIGEGV) at
0xdeadbaad (code=1), thread 1870 (Thread-97)" which is a segfault, in
Androidvania.

Ideally I want to be outputting that mapInstance variable that's commented
out to archive, but for sanity's sake I made a silly little Classroom class,
which I'll include for sanity's sake:

    class Classroom
    {
        friend class boost::serialization::access;

        template <class Archive>
        void serialize( Archive &ar, const unsigned int version )
        {
            ar & studentCount;
        }

        int studentCount;

    public:
        Classroom()
        {
            studentCount = 1;
        }
        ~Classroom(){}
    };

I've run across several red flags about wchar support in Android or on gcc
versions, so I'm inclined to think that's related. Then again, it appears as
though my boost configuration files were aware of the compiler version when
it built (that Mystic Tree link at the top really does seem to be on top of
things, if anyone's interested), which is how the program was able to
compile and run, at all.

I'm almost 100% certain this is related to the Android NDK, either the gcc
version or the gnu-stl, because I can compile and run this code on Windows
through Visual studio with no problem, but it crashes on Android. I've made
sure that my app has write permissions to the internal storage being used. I
can even write out text files using basic std::ostreams without a crash.

I am not at all familiar with dealing with these sorts of compiler- or
platform-specific issues; I have a bachelor's in SE which taught me design
patterns, architecture, and project management, but nothing like this. I'd
greatly appreciate some direction in learning how to work through these
kinds of problems, (although I'd even more greatly appreciate an actual
solution to the problem I'm seeing).

Thanks in advance for any assistance.

--
View this message in context: http://boost.2283326.n4.nabble.com/Android-segfault-while-writing-to-archive-during-Serialization-tp4643096.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net