   STL vectors and dll
  I have a project where everything was a single executable application and was working ok. I divided the project into some dll, so I can have a separate module for OpenGL, LodingMesh, etc.I finally integrate everything correctly, it compiles without problems but I can't find the reason why it crashes when calling the following lines.void DisplayControl::SomeOptionToRender(){...for(itNodes = m_nodeList.begin();    itNodes != m_nodeList.end(); itNodes++ )    {std::vector<ColorRGB*>::iterator itColor = (*itNodes)->GetColorList().begin();   std::vector<TriangleFaces*>::iterator itFaces = (*itNodes)->GetFacesList().begin();std::cout<<(*itNodes)->GetFacesList().size()<<std::endl;   for(itFaces = (*itNodes)->GetFacesList().begin(); itFaces != (*itNodes)->GetFacesList().end(); ++itFaces)   {   ...   }   }}m_nodeList is passed as a reference from another module to the DisplayControlModule. I can notice its content is correct and also it renders correctly when I don't use inner container (i.e. (*itNodes)->GetFacesList()). This worked correctly before, so think it has something to do with the dll?The log prints the correct amount of facesList, but by just calling the lineitFaces != (*itNodes)->GetFacesList().end()the crash is produced. The following message is displayed:Debug assertion failed!Expression: vector iterators incompatible[help]   
  It sounds like you've compiled the dll and executable with different settings that introduce a binary incompatability.I don't know the specifics, but check for example that you aren't compiling the dll with debug iterators and the executable without, or vice versa.Or more generally, make sure you're compiling the dll source code with the same compiler flags as the executable._SECURE_SCL and _HAS_ITERATOR_DEBUGGING are two preprocessor macros to watch out for in particular.   ;  Thanks, that helped me, I added all pre compiled headers for the Dll's and exe with the macros:#define _HAS_ITERATOR_DEBUGGING 0#define _SECURE_SCL 0It compiles and runs the same, but now the crash, Access violation reading location C....Also found  Debug iterator support and I have all that flags set. Very annoying... BTW this build is of course in DEBUG mode and using VC++2008.[Edited by - itzjac on May 14, 2010 7:37:08 PM];Quote:Original post by itzjacThanks, that helped me, I added all pre compiled headers for the Dll's and exe with the macros:*** Source Snippet Removed ***It compiles and runs the same, but now the crash, *** Source Snippet Removed ***Also found  Debug iterator support and I have all that flags set. Very annoying... BTW this build is of course in DEBUG mode and using VC++2008.Ok, so what does the debugger and/or stack trace tell you?Additionally, have you confirmed that you are compiling the dll and executable with identical compiler settings (strictly speaking they don't need to be identical, but it's safest if you're not used to this kind of thing).Lasltly, which CRTs are your dll and exe linked against?   ;Unhandled exception at 0x714a3015 (Render.dll) in ClientApplication.exe: 0xC0000005: Access violation reading location 0xfeeefefa.The log show a vector with size 2, but can't print std::cout<<(*itFaces)->a<<", "<<(*itFaces)->b<<", "<<(*itFaces)->c<<std::endl;;Quote:which CRTs are your dll and exe linked against?Oh, sorry every project has the Multi-threaded Debug DLL (/MDd)   ;  Generally: Attempting to pass C++ templates across DLL boundaries is a bad idea. Not only does everyone have to be using the same CRTs, but they also usually need to be the exact same versions. Even then things can still go bad.   ;Quote:Original post by itzjacQuote:which CRTs are your dll and exe linked against?Oh, sorry every project has the Multi-threaded Debug DLL (/MDd)Ok, so what does the debugger and/or stack trace tell you? Additionally, have you confirmed that you are compiling the dll and executable with identical compiler settings?Quote:0xC0000005: Access violation reading location 0xfeeefefa.That address is suspicious. It could indicate you're accessing an object whose memory has already been freed.   ;Quote:Generally: Attempting to pass C++ templates across DLL boundaries is a bad idea.Could be that only using STL port is solution for this problem? I don't really like the idea, but if there is no other workaround...   ;  The only problem was the way I was getting the vector container, before it was:std::vector<TriangleFaces> GetFacesList(){return m_triangleFacesList;}and now should be:const std::vector<TriangleFaces>& GetFacesList(){return m_triangleFacesList;}No need to have anywhere:#define _HAS_ITERATOR_DEBUGGING 0#define _SECURE_SCL 0That old code that used to work using mingW compiler in CodeBlocks, had no issues with the way retrieve the vector's content, but for VC++9 compiler won't work without using the container by reference. So it works now.   