juce_Atomic::compareAndSetValue -> access violation in RTAS


I get an unhandled exception with an access violation in the “juce_Atomic::compareAndSetValue” method in an RTAS plugin on windows.
Is it possible that the fact that the RTAS PlugInLibrary is by default compiled with 2byte alignment makes any problems here?

This is code where the access violation occours (juce_Atomic line 366):

#elif JUCE_ATOMICS_WINDOWS return sizeof (Type) == 4 ? castFrom32Bit ((int32) juce_InterlockedCompareExchange ((volatile long*) &value, (long) castTo32Bit (newValue), (long) castTo32Bit (valueToCompare))) : castFrom64Bit ((int64) juce_InterlockedCompareExchange64 ((volatile __int64*) &value, (__int64) castTo64Bit (newValue), (__int64) castTo64Bit (valueToCompare)));

This code is called by a SpinLock in the IIRFilter class:

void IIRFilter::processSamples (float* const samples, const int numSamples) noexcept { const SpinLock::ScopedLockType sl (processLock);

This is a simple test plugin with just a call to an IIRFilter->processSamples in the processBlock.
The plugin and IIRFilter works fine for every other plugin format but crashes RTAS.

The juce_Atomic::compareAndSetValue is called pretty often in the plugin without any problems as long as it isn’t called from the DigiPlatformSupport.dll Thread.
All the calls to juce_Atomic::compareAndSetValue from any other Thread (MessageThread) do not make any problems for the RTAS plugin but the SpinLock of the IIRFilter calls this from the DigiPlatformSupport.dll Thread and that results in an access violation.

Any idea what could be specific to the RTAS code? Maybe the 2byte alignment could be the problem?


No… that’s not it. This code:

char n[32] = { 0 }; SpinLock* s = (SpinLock*) (n + 1); s->enter();

…works for me, so alignment isn’t the problem.

The most likely reason for that to be crashing is if your object is actually a dangling pointer.


As always you were right - it was a dangling pointer.
A sidechain input tried to use an IIRFilter object that was already cleaned up.
Why is it that you’re always right?!