map<std::string, boost::shared_ptr<BlackVolTermStructure>> crashes on destruction - Excel add-in

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

map<std::string, boost::shared_ptr<BlackVolTermStructure>> crashes on destruction - Excel add-in

Pedro Milet

Dear all,


I am writing an Excel add-in in C++ using XLW and QuantLib.

In order to store a set of volatility curves, I am using the following map:


typedef boost::shared_ptr<QuantLib::BlackVolTermStructure> VolTermStructure;

std::map<std::string, VolTermStructure> volTermStructureMap;


Now I have a “SetVolSurface” method that does the following (for simplicity, I’ll only show the Constant Vol curve which already exhibits the issue):


volTermStructureMap[surfaceID]  = VolTermStructure( new BlackConstantVol(0,





[vol is a double,  cal is a std::shared_ptr<const QuantLib::Calendar> and dayCounter is a std::shared_ptr<const QuantLib::DayCounter>]


Everything compiles and run fine, and I can extract useful information from it (blackVol, blackVariance etc).

However, while Debugging, if I close Excel the following error occurs:


Exception thrown: read access violation.


boost::unordered::detail::table<boost::unordered::detail::set<std::allocator<QuantLib::Observer * __ptr64>,QuantLib::Observer * __ptr64,boost::hash<QuantLib::Observer * __ptr64>,std::equal_to<QuantLib::Observer * __ptr64> > >::get_bucket(...) returned 0xFFFFFFFFFFFFFFFF.


If there is a handler for this exception, the program may be safely continued.



Am I doing something wrong? Is this a bug? I’ve tried a few versions of the above code without success.


A few points:

-          The error does not occur if I don’t populate the map using the SetVolSurface method – if I prepopulate the map, for instance, I can close Excel without getting the error.

-          The error does not occur if I hit the “Stop debug” button instead of closing Excel

-          The error does not occur if I compile the Release version of the add-in, open Excel, and map the add-in from Excel (but I’m worried that there is a silent memory error under the hood).


Thanks in advance,

Pedro Milet

Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
QuantLib-users mailing list
[hidden email]