DirectX + Obj + Boost::Serialization

Started by
1 comment, last by TheOrestes 11 years, 3 months ago

Hi,

Recently I wrote a very basic Obj format loader in DIrectX, thanks to this wonderful article by Adel Amro : http://my.opera.com/adelamro/blog/direct3d-obj-viewer-sample

Obj file was taking time to load. I decided to give Boost's binary serialization a try just to check if after converting data into custom mesh format in binary if I get any speed benifits or not. Just to keep things very simple to begin with, I simply chose 4 members to be a part of my custom mesh format : vertex buffer, index buffer, attribute buffer & custom material structure just as blog above uses.

To start off with, i chose boost::text_archive to get hang of boost, am using Boost for the very first time. I was able to successfully read data from obj into my own data format & later use my data format to render it on the screen. This assured that all the required setup to render the mesh was correct & properly set.

Then I switched to boost::binary_archive. I was able to write the data in Binary format, but when I tried loading it, I got error which hangs up at following code inside boost library. Am absolutely beginner in boost & not able to dig down the root cause for the error. The error occurs at following line inside "boost_binary_iprimitive.hpp" file :


 std::streamsize s = static_cast<std::streamsize>(count / sizeof(Elem));
    std::streamsize scount = m_sb.sgetn(
        static_cast<Elem *>(address),
        s
    );
    if(scount != s)
        boost::serialization::throw_exception(
            archive_exception(archive_exception::input_stream_error)
        );

where the value of s is 4 & scount is 2, which throws the exception. Can anyone let me know what am I doing wrong & what causes for this type of error?

Thanks,

TheOrestes.

Advertisement

Boost is a very stable library to use, so I really doubt that looking at this code will help you.

However, from the callstack, you can check from where boost is getting invoked in your code, and then check if something is wrong with the values in you method call.

And, in the worst case scenario, even if it's an issue in Boost then you should probably check on Boost forums, not here.

Hi,

thanks for the reply. Well the reason for giving BOOST code is just to get idea which exception is occuring. I completely agree with Bosst's stability :)

as per the more info, this error is triggered right when I try to create the input archive of a file whose output archive has been successfully created.


std::ifstream ifs(filename.c_str());
    if(ifs.good())
    {
        boost::archive::binary_iarchive ia(ifs);
        ia >> BOOST_SERIALIZATION_NVP(objMesh);
        ifs.close();
        MessageBox(0, "Loading Done", "Success!", MB_OK);
    }

Cheers.

This topic is closed to new replies.

Advertisement