Crash after clearing and copying between OwnedArrays on PC only

(Using JUCE 6.0.7, due to third-party requirements currently.)

I have an OwnedArray of some objects, which is defined to store the base class of an object that can be one of three sub-classes. At one point, I make a copy of the array by iterating through, and creating new objects for the second copy of the array, using the copy constructors of the three sub-classes to create new instances of each object. Since this second copy of the array may already have data copied to it previously, I first call clear() on the second array, to delete the objects in it and empty the array.

This was all working well while developing on the Mac, but when I ported to the PC, we started seeing crashes in STudio One (when using an ARA+VST3 version of the plugin). They’re heap errors that occur when drawing a line, sometime after having copied the array data to another array and later cleared that copy and copied updated data from the original array.

Sometimes I have managed to get an error when clearing the second array itself, but trying to debug that doesn’t seem to have led me anywhere. Most of the time, though, it just goes merrily along until it goes to draw my graph lines, which aren’t related to the data that was copied or its copy in any way.

My objects are polymorphic, but they follow the “rule of three”, having virtual destructors, copy constructors, and copy assignment operators. So I don’t thin the problem lies there. Plus, as I said, it works without any problems on the Mac, and may go through several copy operations before the graph redraw throws an exception in ntdll while calling drawLine(). (It’s deep inside that code, when calling heap_alloc_dbg_internal.) The Output window only shows this:
Critical error detected c0000374

Any ideas? I haven’t been able to get Address Sanitizer working on either Mac or PC. And I can’t use another host like AuioPluginHost, because this only happens with the ARA version of our plugin. So I assume it’s something to do with the object we’ve copying to being copied or moved in memory or something, but I don’t know in what way or how to find out where it’s going wrong on the PC.

I thought of changing to a std::vector, but there are so many lines of code currently referencing the OwnedArray that that would take a few hours to modify, and no guarantee it would change anything at all.

Are you making a deep copy or just copying the pointers?

You probably need to create a deep copy with new objects for the “copy”

Rail

Damn. Red herring. Removing everything related to that copy makes no difference. So it’s not actually related to copying that data. Never mind. :frowning:

Is there any tool I can use to find where I’m corrupting the heap in a plugin on the PC?