Detecting heap corruption in plugin on PC?

Is there any way to detect where/when a heap corruption has occurred, when running a plugin in the debugger in Visual Studio (2019)?

I have a VST3 plugin that works fine on Mac, but when closing the plugin on the PC, it crashes in ntdll with a message about a heap corruption. I tried turning on “Enable Diagnostic Tools when debugging”, and “Enable Windows debug heap allocator”, and once running I enabled “heap profiling”, but don’t see anything in the Output window or in any of the debugger windows when running, and the code hits the exception when there is nothing related to my plugin in the call stack.

I also tried selecting “Enable native corruption detection” in the Diagnostic Tools’ Memory Profiler Tool, but again I don’t see anything in the Output window or diagnostic windows to tell me when/where the heap corruption happened; only that it breaks in ntdll, which has no source code available, naturally.

I’ve tried Google searches and looking at posts here (including mine from a previous similar experience), but everything seems to talk about how to deal with heap corruption in an executable, not in a dll. I’m at a loss as to how to locate this heap corruption which only seems to happen on Windows (even though I don’t have any code other than inside the JUCE library itself that differs between Mac and PC).

Any ideas? I’ve combed through my code for a couple of weeks now, improving things here and there, but this problem persists. :frowning:

You could try building both the host and the plugin with some memory diagnostic tool. I’d recommend trying out Address Sanitizer, which is available in newer versions of Visual Studio. I often do this on macOS/Linux to debug memory issues using the AudioPluginHost. Although ASAN is quite new on Windows, and I haven’t had many opportunities to try it out, I expect that the same setup should work there.

But I can’t rebuild Studio One, which is the host I have to use for this (because it’s actually an ARA plugin built on the JUCE VST3 wrapper code).