I have a singleton class (EventManager) in a static lib that gets linked by both the .exe and a dynmic lib. Events are passed around as std::shared_ptr<IEvent>. The EventManager stores all queued events in a std::list and pops them out after handling them. This works fine as long as all events were added from the exe. If I add events from inside the DLL, pop_front throws an exception at the last event that was added from inside the DLL. It doesn't matter whether the DLL adds one event or 1000, only the one that was added last throws the exception.
This is the exception:
Debug Assertion Failed! Program: ...ts\visual studio 2013\Projects\QueueTest\Debug\DynamicLib.dll File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c Line: 1424 Expression: _pFirstBlock == pHead
I'm using the Visual Studio 2012 with compiler for this.
I know that you should not deallocate memory in any module other than the one that allocate the memory. However, from what I've read std::shared_ptr can be used to avoid this problem as it contains a pointer to the deleter for the memory.
I attached a sample project with this problem to this post.
Any ideas on how I can get the EventManager to work with events coming from a DLL?