Strange error when debugging AudioUnit

I’m trying to find the error of my Tremolo AudioUnit. It is an adapted version of the TremoloUnit Demo from apple (https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/AudioUnitProgrammingGuide/Tutorial-BuildingASimpleEffectUnitWithAGenericView/Tutorial-BuildingASimpleEffectUnitWithAGenericView.html)

Now in my processBlock method I have this line of code:
waveArrayIndex = static_cast(myNumOfProcessedSamples * myCurrentScale) % myWaveArraySize;

The participating variables are declared as:
int waveArrayIndex;
long myNumOfProcessedSamples;
float myCurrentScale;
int myWaveArraySize;

So before waveArrayIndex has been initialized I can access it in the debugger. Right after this particular line of code XCode gives me this error:

Process 15602 resuming
(lldb) p waveArrayIndex
error: field ‘holder’ declared with incompatible types in different translation units (‘SharedRef’ (aka ‘juce::ReferenceCountedObjectPtr<juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::SharedPointer>’) vs. ‘SharedRef’ (aka ‘juce::ReferenceCountedObjectPtr<juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::SharedPointer>’))
note: declared here with type ‘SharedRef’ (aka ‘juce::ReferenceCountedObjectPtr<juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::SharedPointer>’)
error: 1 errors parsing expression

Does anyone have an idea what I’m doing wrong? I ran out of ideas what

Strange error since I assume you aren’t using sharedptr or reference counted obj?

Anyways,

static_cast needs a template argument:
http://en.cppreference.com/w/cpp/language/static_cast

I also don’t understand why you are using casting, those basic types shouldn’t have any issues, but try static_cast <-int> (calculation)

Just realized the forum formatting probably removed your static_cast<-int>, as it did for my post. not sure! perhaps we need some more info

No, I don’t use sharedptr or reference counted obj (I don’t even know what this is for - let’s not start on that). So I tested if that bitch works if comment everything out that could cause trouble. Turns out it still crashes - wait, not necessarily crashes, it just fails to print the value in the debugger. So here is my whole new processBlock method. Maybe this information helps:

void TremoloAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
const int totalNumInputChannels = getTotalNumInputChannels();
const int totalNumOutputChannels = getTotalNumOutputChannels();

float *channelData;
int myDamnTestVar;

for (int channelIndex = 0; channelIndex < totalNumInputChannels; ++channelIndex) {
    for (int sampleIndex = 0; sampleIndex < buffer.getNumSamples(); ++sampleIndex) {
        channelData = buffer.getWritePointer (channelIndex, sampleIndex);
        myDamnTestVar++;
    }
}   

}

When I try to print myDamnTestVar it works sometimes (in most cases the first time before it has been initialized, the next time it fails and then it seems to work). Here’s the output of my debugger:
JUCE v4.2.3
(lldb) p myDamnTestVar
(int) $0 = 1
(lldb) c
Process 16278 resuming
(lldb) p myDamnTestVar
error: field ‘holder’ declared with incompatible types in different translation units (‘SharedRef’ (aka ‘juce::ReferenceCountedObjectPtr<juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::SharedPointer>’) vs. ‘SharedRef’ (aka ‘juce::ReferenceCountedObjectPtr<juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::SharedPointer>’))
note: declared here with type ‘SharedRef’ (aka ‘juce::ReferenceCountedObjectPtr<juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::SharedPointer>’)
error: 1 errors parsing expression

Thank you for helping me!

It seems like Xcode’s debugger is confused by something. I’m getting that a lot these days. Try using a lot of DBG statements to get a better picture of what is actually happening.

Can you elaborate what you mean with “a lot of DBG statements”? I’ll just start the plug-in from scratch, becaue I don’t know what else to do…

Cheese, Luke

One more thing!
When I leave the processBlock method uncommented, it compiles just fine. The first time it even validates with the auval commandline tool. The second time auval gives me this error with the render tests:

RENDER TESTS:

Input Format: AudioStreamBasicDescription: 2 ch, 44100 Hz, ‘lpcm’ (0x00000029) 32-bit little-endian float, deinterleaved
Output Format: AudioStreamBasicDescription: 2 ch, 44100 Hz, ‘lpcm’ (0x00000029) 32-bit little-endian float, deinterleaved
Render Test at 512 frames
/usr/bin/auval: line 11: 627 Segmentation fault: 11 arch -x86_64 /usr/bin/auvaltool “$@”

Unfortunately I could not reproduce the Segmentation Fault. I have no idea what causes it - I think I checked all my pointers and buffers…

UPDATE:

I now recoded a much simpler version of my plugin from scratch. I kept the processBlock as simple as possible. Still the same error. My plugin compiles just fine though…
If someone still is interested, here is the guts of my processing code:

class TremoloAudioProcessor : public AudioProcessor
{
//standard JUCE code
private:
//==============================================================================
void filterKernel();

AudioParameterFloat *parameterRate;
AudioParameterFloat *parameterDepth;

enum {waveArraySize = 2000};
float sineArray[waveArraySize];
float *waveArrayPtr;
float currentScale;
float nextScale;
long numProcessedSamples;
enum {sampleLimit = (int)10E6};

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TremoloAudioProcessor)

};

TremoloAudioProcessor::TremoloAudioProcessor()
{
//AudioParameterFloat (ParameterID, Name, min, max, default)
addParameter(parameterRate = new AudioParameterFloat( “rate”,
paramName_Tremolo_Rate,
minimumValue_Tremolo_Rate,
maximumValue_Tremolo_Rate,
defaultValue_Tremolo_Rate));

addParameter(parameterDepth = new AudioParameterFloat(  "depth",
                                                        paramName_Tremolo_Depth,
                                                        minimumValue_Tremolo_Depth,
                                                        maximumValue_Tremolo_Depth,
                                                        defaultValue_Tremolo_Depth));

filterKernel();

numProcessedSamples = 0;
currentScale = 0.0;

}

void TremoloAudioProcessor::filterKernel (void)
{
//create the wavetable for a sinewave LFO
for (int i = 0; i < waveArraySize; ++i) {
double radians = i * 2.0 * M_PI / waveArraySize;
sineArray[i] = (sin(radians) + 1.0) * 0.5; //the sine function shall range from 0 to 1
}
}

void TremoloAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
int testVar;

const int totalNumInputChannels  = getTotalNumInputChannels();
const int totalNumOutputChannels = getTotalNumOutputChannels();

for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
    buffer.clear (i, 0, buffer.getNumSamples());

for (int sampleIndex = 0; sampleIndex < buffer.getNumSamples(); ++sampleIndex) {
    for (int channelIndex = 0; channelIndex < totalNumInputChannels; ++channelIndex) {
        float* channelData = buffer.getWritePointer (channelIndex, sampleIndex);
        *channelData = 0.0;
        channelData++;
        
        testVar = testVar+1;
        
        
    }
}

}


When I try to print testVar in the processBlock method I’ll get this error. Only the second time I read the value of this variable. The error again goes like this:
JUCE v4.2.3
JUCE v4.2.3
(lldb) p testVar
(int) $0 = 28672
(lldb) c
Process 996 resuming
(lldb) p testVar
error: field ‘holder’ declared with incompatible types in different translation units (‘SharedRef’ (aka ‘juce::ReferenceCountedObjectPtr<juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::SharedPointer>’) vs. ‘SharedRef’ (aka ‘juce::ReferenceCountedObjectPtr<juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::SharedPointer>’))
note: declared here with type ‘SharedRef’ (aka ‘juce::ReferenceCountedObjectPtr<juce::WeakReference<juce::Component, juce::ReferenceCountedObject>::SharedPointer>’)
error: 1 errors parsing expression

Maybe it has something to do with the host application, that was provided by JUCE for debugging…

This to me looks like a bug with the debugger. Nothing really in your code. If you want to know the value of the variable, print it to the console with the DBG method, for exmaple, in your processBlock method:

DBG (testVar);
1 Like

Ah okay! There is a DBG define, which is quite nice. Yeah it’s a bug in the debugger, I think. I already reported it at http://bugreporter.apple.com/
Turns out my plugin not working had nothing to do with this bug.
Thanks!