<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:59:49 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CXX-637] OID.init() exception when MongoDB Driver is used in DLL</title>
                <link>https://jira.mongodb.org/browse/CXX-637</link>
                <project id="11980" key="CXX">C++ Driver</project>
                    <description>&lt;p&gt;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!&lt;/p&gt;

&lt;p&gt;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. &lt;/p&gt;

&lt;p&gt;Additional hint:&lt;br/&gt;
For me it is mandatory to use the MongoDB driver in a DLL, the older drivers (v2.4.x and 2.5.x worked fine, the 26compat driver was only tested a little, therefore I can not tell anything about this. &lt;/p&gt;

&lt;p&gt;How to reproduce the problem:&lt;br/&gt;
1. I used Visual Studio 2010SP1 to generate the MongoDB driver and I used Boost 1.51 to create the driver. I used the followed scons call:&lt;/p&gt;

&lt;p&gt;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&lt;/p&gt;

&lt;p&gt;I created also the remeining possible driver versions as stated in the description:&lt;/p&gt;

&lt;p&gt;  scons $ARGS install&lt;br/&gt;
  scons $ARGS install --dbg=on&lt;br/&gt;
  scons $ARGS install --dynamic-windows --sharedclient&lt;br/&gt;
  scons $ARGS install --dynamic-windows --sharedclient --dbg=on&lt;/p&gt;

&lt;p&gt;2. I created a DLL and I exported a function using the followed code:&lt;/p&gt;

&lt;p&gt;#include &amp;lt;WinSock2.h&amp;gt;&lt;br/&gt;
#include &amp;lt;Windows.h&amp;gt;&lt;br/&gt;
#include &amp;lt;cstdlib&amp;gt;&lt;br/&gt;
#include &amp;lt;iostream&amp;gt;&lt;br/&gt;
#include &quot;mongo/client/dbclient.h&quot; // for the driver&lt;/p&gt;

&lt;p&gt;extern &quot;C&quot; __declspec(dllexport) void Test()&lt;/p&gt;
{
  mongo::OID oid;
  oid.init(); // &amp;lt;-- Here occurs the problem
  std::string str=oid.toString();
}

&lt;p&gt;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-&amp;gt;() the assert will be triggered because px is 0.&lt;/p&gt;</description>
                <environment></environment>
        <key id="215831">CXX-637</key>
            <summary>OID.init() exception when MongoDB Driver is used in DLL</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="andrew.morrow@mongodb.com">Andrew Morrow</assignee>
                                    <reporter username="ThomasM">Thomas M. [X]</reporter>
                        <labels>
                            <label>legacy-cxx</label>
                    </labels>
                <created>Thu, 9 Jul 2015 10:44:43 +0000</created>
                <updated>Tue, 6 Dec 2016 07:34:05 +0000</updated>
                            <resolved>Thu, 9 Jul 2015 11:41:01 +0000</resolved>
                                    <version>legacy-1.0.3</version>
                                                    <component>API</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="961994" author="acm" created="Thu, 9 Jul 2015 11:41:01 +0000"  >&lt;p&gt;Happy to hear that adding the initialization fixed the problem. I&apos;ve added some additional documentation to the wiki here:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-cxx-driver/wiki/Download-and-Compile-the-Legacy-Driver#using-the-driver-in-your-application&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-cxx-driver/wiki/Download-and-Compile-the-Legacy-Driver#using-the-driver-in-your-application&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="961989" author="thomasm" created="Thu, 9 Jul 2015 11:13:16 +0000"  >&lt;p&gt;Hello Andrew&lt;/p&gt;

&lt;p&gt;You are correct, in my DLL Test code and in the real code also &quot;mongo::client::initialize()&quot; 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.&lt;br/&gt;
When I converted the code I focussed on compiler errors / warnings to be compatible to the new driver.&lt;/p&gt;

&lt;p&gt;At all Andrew, a lot thanks, I guess I&apos;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...&lt;/p&gt;

&lt;p&gt;Best regards&lt;/p&gt;

&lt;p&gt;Thomas&lt;/p&gt;</comment>
                            <comment id="961984" author="acm" created="Thu, 9 Jul 2015 10:55:47 +0000"  >&lt;p&gt;Thanks for the detailed writeup. First, I want to verify that you didn&apos;t literally type $ARGS for those builds, because if so that isn&apos;t going to do what you think it does. Given your command line example at the beginning, the correct set of invocations should be:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;scons --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&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;scons --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 --dbg=on&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;scons --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&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;scons --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&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-cxx-driver/wiki/Configuring%20the%20Legacy%20Driver#the-mongoclientinitialize-function&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-cxx-driver/wiki/Configuring%20the%20Legacy%20Driver#the-mongoclientinitialize-function&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Could you try adding a call to mongo::client::Initialize and see if the crash you are experiencing goes away?&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hsb25r:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>