Static Linking MSVCRT

I'm looking at moving to using static linking for the Microsoft C Run Time lib in my plug-in, so that I can avoid any potential DLL versioning issues (DLL hell, as it's sometimes referred to).  This all seems to work fine except that I noticed when I'm debugging my plug-in with the Juce Plug-in Host I get an exception is thrown in HeapFree when the Plug-in Host is being shut down for the VST2 version.  For the VST3 version I get a whole bunch of memory leak errors.

I've also been able to reproduce this bug with the Juce Demo Plug-in (sources are about 1 month behind the tip), but I have to make sure that the Plug-In Host is built with a different version of Visual Studio (actually the platform toolset).  This sounds like a problem where a memory deallocation is occurring from a different version of the CRT than the same memory was allocated from.

This problem doesn't seem to happen with the 3 other hosts I tried (Cubase, Studio One and PT), so maybe I could just live with the bug.  But I am concerned that I might have some lurking issue which will show up in other hosts from time to time.  And of course it would be nice to not hit all of these expectations when I'm debugging.

Any ideas what's going on exactly and how to fix this bug?

Thanks,
Chris
 

When you load a debug plugin in the debug host, the runtime can often mix up symbols between the two modules. Try it with a stripped release build of the host or a release build of the plugin and it'll probably be ok.

This actually seems to be a problem related to the Visual Studio 2012 toolset.  If statically link that toolset to my plug-in then I get the error.  It doesn't matter what toolset the Juce PlugIn Host uses, so it's not a mismatch of toolsets, although I think it is still related to having different instances of CRT running.  Maybe the 2012 toolset changed something about how it cleans up it's memory allocations.

Even when using the release build of the plug-in or the host I get the exceptions.  If these really are benign I would like to find a way to suppress them.  

Here are the errors from the console output.  The leaked object asserts make me think that this is not just due to a spurious exception in the debugger, but some actual change in program execution.  Any ideas?

 

VST2:

HEAP[Plugin Host.exe]: HEAP: Free Heap block 343d8a8 modified at 343d8d0 after it was freed
Plugin Host.exe has triggered a breakpoint.
 

VST3:


*** Leaked objects detected: 1 instance(s) of class ContentWrapperComponent
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class OwnedArray
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class TimerThread
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class Thread
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class LookAndFeel_V2
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class LookAndFeel
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class Desktop
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class ComponentAnimator
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class OwnedArray
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class MouseInputSource
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class MouseInputSourceInternal
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class OwnedArray
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class TypefaceCache
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 3 instance(s) of class WaitableEvent
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 5 instance(s) of class AsyncUpdater
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class Component
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class MouseCursor
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 2 instance(s) of class JuceVST3Editor
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class JuceVST3EditController
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class MessageManager
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
*** Leaked objects detected: 1 instance(s) of class JuceLibraryRefCount
JUCE Assertion failure in juce_leakedobjectdetector.h:95
Plugin Host.exe has triggered a breakpoint.
 

 

Those are global objects that would be freed when shutdownJuce_GUI is called, which happens when the host releases all the VST3 objects that it's using. I can't be certain, but that leak looks to me like the host is unloading the plugin DLL before it has properly freed all the objects it was using.

It's possible the VST3 thing is a different bug.  When I open the Juce Demo VST3 GUI it is all black.  If I don't open the GUI then I don't get those asserts but I do get the heap exception just like the VST2 version does.  I'm a little bit behind, so I'll test with the tip, since that might be fixed.