Skip to main content
October 20, 2010
Answered

Is It can not use boost::archive::binary_iarchive in develop ai plugin?

  • October 20, 2010
  • 3 replies
  • 6416 views

if you write these code in you program:

#include <boost/serialization/access.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
            std::ifstream ifs("d:\\haha");
            boost::archive::binary_iarchive ia(ifs);

plug-in can't be load;

is it a bug?

This topic has been closed for replies.
Correct answer rkansal

Hi,rkansal ,Can I use MSN communicate with you? I want to give you some screenshots.


Hi,

I looked at your code and tried to debug your problem.

The problem is happenning because boost's serialization creates a static singleton instance. The static members are initialized at the time of dll attach, so before calling any function of the plugin, boost tries to allocate memory for the static instance.

You have included ASMemory.cpp which overrides the new operator, therefore this new operator is called at the time of static member construction.

However new fails to allocate memory since spBlock suite is not acquired by the plugin yet!

I hope it helped you in understanding the cause of the failure.

Having said that, I will suggest try the following solutions:

1. Simplest one is to remove the ASMemory.cpp from your project so that default CRT new is called instead.But, it has a risk. If you pass memory pointer to some other AI API which tries to deallocate it, you are going to be in trouble. So, watch it!

2. Try to build a dynamic linked version of boost lib so that you dont have to link statically against it. That way, AI will not interfere with the memory management of boost, but it also has a risk. If you pass a pointer of some object to boost and for some reason, it keeps and tries to destroy it later, it might be a problem. This possiblity could be eliminated by checking the function documentation which you are going to use from the boost library.

Try to see which one suits you, and let me know if you have any more questions/doubts.

I hope it helped!

3 replies

Participating Frequently
October 21, 2010

Hi,

I would like to help you, but I need some more info like:

1. What is the exact place where you placed this code? I want to understand the timing of this execution.

2. Did you try catching the exceptions? You could place this piece of code inside a try-catch and see if boost/std throws an exception due to some FS error or otherwise.

--

Ruchin

A. Patterson
Inspiring
October 21, 2010

Be careful about static global variables. We've had trouble in the past with them for some reason, I can't remember exactly why. Try declaring them inside your entry point and see if you still have trouble.

A. Patterson
Inspiring
October 21, 2010

I should qualify that -- globals are fine for the most part. But if it doesn't load and you've got a global variable that's a fairly complex object, I'd try deferring creation.  Global strings, integers, that kind of thing are fine.

October 20, 2010

when I add those code to anywhere in my project.

#include <boost/serialization/access.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
            std::ifstream ifs("d:\\haha");
            boost::archive::binary_iarchive ia(ifs);

when debug, VC debug output windows shows:

"Illustrator.exe ": Loaded" C: \ Program Files (x86) \ Adobe \ Adobe Illustrator CS4 \ Plug-ins \ fp.aip ", loaded symbols.

Illustrator.exe the 0x75a0b727 of the most likely exception: Microsoft C + + exception: the memory location 0x0018f404 at std:: bad_alloc.

"Illustrator.exe": uninstalled "C: \ Program Files (x86) \ Adobe \ Adobe Illustrator CS4 \ Plug-ins \ fp.aip "

fp.aip  is build by my project.

Is it a bug of boost or  illustrator?

October 20, 2010

when I add those code to anywhere in my project.

#include <boost/serialization/access.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
            std::ifstream ifs("d:\\haha");
            boost::archive::binary_iarchive ia(ifs);

when debug, VC debug output windows shows:

"Illustrator.exe ": Loaded" C: \ Program Files (x86) \ Adobe \ Adobe Illustrator CS4 \ Plug-ins \ fp.aip ", loaded symbols.

Illustrator.exe the 0x75a0b727 of the most likely exception: Microsoft C + + exception: the memory location 0x0018f404 at std:: bad_alloc.

fp.aip  is build by my project.

October 20, 2010

My illustrator is CS4