[CXX-637] OID.init() exception when MongoDB Driver is used in DLL Created: 09/Jul/15 Updated: 06/Dec/16 Resolved: 09/Jul/15 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | API |
| Affects Version/s: | legacy-1.0.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Thomas M. [X] | Assignee: | Andrew Morrow (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | legacy-cxx | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
At all this problem exist only if the compiled MongoDB Driver is used in a DLL Target. If the same files will be used in a DLL, than this particular problem does not occur! In my real target the problem occur when using the Macro GENOID or mongo::BSONObjBuilder().genOID()... Since I did not found the reason for this problem in my DLL project I was guessing this problem is because the Mongo driver is used in a DLL not an executable. Additional hint: How to reproduce the problem: scons.py --prefix=E:\LibraryBuild\mongo-cxx-driver-legacy-1.0.3\mongoDriver --cpppath=E:\LibraryBuild\boost_1_51_0 --libpath=E:\LibraryBuild\boost_1_51_0\stage\x64\lib-boost --64 install --dynamic-windows --sharedclient --dbg=on I created also the remeining possible driver versions as stated in the description: scons $ARGS install 2. I created a DLL and I exported a function using the followed code: #include <WinSock2.h> extern "C" __declspec(dllexport) void Test() { mongo::OID oid; oid.init(); // <-- Here occurs the problem std::string str=oid.toString(); }The exception occurs a oid.init(), in OID::init() the function setincrecment is called, in OID::Increment OID::Increment::next() the line is called, than in scoped_ptr.hpp in T* oparator->() the assert will be triggered because px is 0. |
| Comments |
| Comment by Andrew Morrow (Inactive) [ 09/Jul/15 ] | ||||
|
Happy to hear that adding the initialization fixed the problem. I've added some additional documentation to the wiki here: | ||||
| Comment by Thomas M. [X] [ 09/Jul/15 ] | ||||
|
Hello Andrew You are correct, in my DLL Test code and in the real code also "mongo::client::initialize()" is missing. The real code is really old and uses currently the old (2.4.x) driver with MongoDB 2.4.13. When I did the code conversion I missed this important line. Maybe it should be marked red with an additional hint that this line is really important. At all Andrew, a lot thanks, I guess I'd never found this out even if it would be easy to find. I was searching the problem for over a day in the code... Best regards Thomas | ||||
| Comment by Andrew Morrow (Inactive) [ 09/Jul/15 ] | ||||
|
Thanks for the detailed writeup. First, I want to verify that you didn't literally type $ARGS for those builds, because if so that isn't going to do what you think it does. Given your command line example at the beginning, the correct set of invocations should be:
Next, I notice that you do not call ::mongo::client::Initialize in your test. With the legacy driver you must do so before using any part of the API. Please see the following documentation for details: Could you try adding a call to mongo::client::Initialize and see if the crash you are experiencing goes away? |