ADLINK-IST / opensplice

This is the Vortex OpenSplice Community Edition source repository. For our commercial offering see
https://www.adlinktech.com/en/vortex-opensplice-data-distribution-service
Apache License 2.0
259 stars 157 forks source link

Access violation when creating a reader #82

Closed HarryDC closed 5 years ago

HarryDC commented 5 years ago

This is the 190227 version of OSPL built using visual studio 17, win32. In the debug build of the win32 version there is an access violation when trying to create a reader..

Exception thrown at 0x0F0E31A7 (vcruntime140d.dll) in MstaRuntimeTest.exe: 0xC0000005: Access violation reading location 0xCDCDCDCD.

This happens even when the reader is created all with default values, the location looks like its the copy constructor of the ShareDelegate, trigger from line 604 in the common_constructor in TDataReaderImpl.hpp, the stack trace is as follows:

    vcruntime140d.dll!memcpy(unsigned char * dst, unsigned char * src, unsigned long count) Line 657    Unknown
    dcpsisocpp2d.dll!std::char_traits<char>::copy(char * const _First1, const char * const _First2, const unsigned int _Count) Line 471 C++
    dcpsisocpp2d.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Construct_lv_contents(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Right) Line 2403    C++
    dcpsisocpp2d.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Right) Line 2132   C++
    dcpsisocpp2d.dll!org::opensplice::core::policy::ShareDelegate::ShareDelegate(const org::opensplice::core::policy::ShareDelegate & other) Line 2270  C++
    dcpsisocpp2d.dll!dds::core::Value<org::opensplice::core::policy::ShareDelegate>::Value<org::opensplice::core::policy::ShareDelegate><org::opensplice::core::policy::ShareDelegate>(const org::opensplice::core::policy::ShareDelegate & arg) Line 53    C++
    dcpsisocpp2d.dll!org::opensplice::core::policy::TShare<org::opensplice::core::policy::ShareDelegate>::TShare<org::opensplice::core::policy::ShareDelegate>(const org::opensplice::core::policy::TShare<org::opensplice::core::policy::ShareDelegate> & other) Line 66   C++
    dcpsisocpp2d.dll!org::opensplice::sub::qos::DataReaderQosDelegate::DataReaderQosDelegate(const org::opensplice::sub::qos::DataReaderQosDelegate & other) Line 62    C++
>   MstaRuntimeTest.exe!dds::sub::detail::DataReader<Msta::Runtime::Data::Application>::common_constructor(dds::sub::DataReaderListener<Msta::Runtime::Data::Application> * listener, const dds::core::status::StatusMask & mask) Line 604  C++
    MstaRuntimeTest.exe!dds::sub::detail::DataReader<Msta::Runtime::Data::Application>::DataReader<Msta::Runtime::Data::Application>(const dds::sub::TSubscriber<org::opensplice::sub::SubscriberDelegate> & sub, const dds::topic::Topic<Msta::Runtime::Data::Application,dds::topic::detail::Topic> & topic, const dds::core::TEntityQos<org::opensplice::sub::qos::DataReaderQosDelegate> & qos, dds::sub::DataReaderListener<Msta::Runtime::Data::Application> * listener, const dds::core::status::StatusMask & mask) Line 569 C++
    MstaRuntimeTest.exe!dds::sub::DataReader<Msta::Runtime::Data::Application,dds::sub::detail::DataReader>::DataReader<Msta::Runtime::Data::Application,dds::sub::detail::DataReader>(const dds::sub::TSubscriber<org::opensplice::sub::SubscriberDelegate> & sub, const dds::topic::Topic<Msta::Runtime::Data::Application,dds::topic::detail::Topic> & topic, const dds::core::TEntityQos<org::opensplice::sub::qos::DataReaderQosDelegate> & qos, dds::sub::DataReaderListener<Msta::Runtime::Data::Application> * listener, const dds::core::status::StatusMask & mask) Line 298   C++
    MstaRuntimeTest.exe!DdsTest_CreateReader_Test::TestBody() Line 35   C++
    MstaRuntimeTest.exe!testing::internal::HandleExceptionsInMethodIfSupported<testing::Test,void>(testing::Test * object, void(testing::Test::*)() method, const char * location) Line 2482    C++
    MstaRuntimeTest.exe!testing::Test::Run() Line 2499  C++
    MstaRuntimeTest.exe!testing::TestInfo::Run() Line 2678  C++
    MstaRuntimeTest.exe!testing::TestSuite::Run() Line 2806 C++
    MstaRuntimeTest.exe!testing::internal::UnitTestImpl::RunAllTests() Line 5244    C++
    MstaRuntimeTest.exe!testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl,bool>(testing::internal::UnitTestImpl * object, bool(testing::internal::UnitTestImpl::*)() method, const char * location) Line 2482  C++
    MstaRuntimeTest.exe!testing::UnitTest::Run() Line 4845  C++
    MstaRuntimeTest.exe!RUN_ALL_TESTS() Line 2505   C++
    MstaRuntimeTest.exe!main(int argc, char * * argv) Line 64   C++
    [External Code] 

The release build seeming works fine, passing all our tests. Oddly the win-64 build works fine in release as well as with the debug libraries. Is there anyway I can work around this ? Or fix it ?

hansvanthag commented 5 years ago

I've heard about issues before when trying to combine debug- and release-builds of applications- i.c.w. DDS(-library) code .. could that be an issue here too (i.e. are you sure you're not combining a release-built application with a debug-built dds-library and vice-versa) ?

ThijsSassen commented 5 years ago

When using a debug application with a release build of opensplice you also have to set the NDEBUG preprocessor flag in visual studio.

HarryDC commented 5 years ago

@hansvanthag @ThijsSassen, This is using Opensplice built with release but the customlibs built as debug (this method was documented somewhere in the OSPL docs) i.e. here are the dds libraries that I am linking with

D:\tools\dds\9-6-190227-virtualbox\HDE\x86.win32\lib\ddskernel.lib
D:\tools\dds\9-6-190227-virtualbox\HDE\x86.win32\lib\dcpsisocpp2d.lib
D:\tools\dds\9-6-190227-virtualbox\HDE\x86.win32\lib\dcpssacppd.lib

If it makes a difference I can also build all of DDS under debug, but then the documentation should be updated as well.

ThijsSassen commented 5 years ago

@HarryDC When using the debug lib of isocpp2 you need to have set the following flags in visual studio: C/C++ -> Preprocessor -> Add _DEBUG (as well as leaving NDEBUG set) C/C++ -> Code Generation -> set Multi-threaded Debug DLL (/MDd) instead of Multi Threaded DLL (/MD) see also https://istkb.adlinktech.com/article/compiling-isoc2-applications/

HarryDC commented 5 years ago

@ThijsSassen I missed setting NDEBUG in my own project, thanks (under 64bit builds this does seem to be necessary), that has done the trick. Thanks