Juce demo crash in audio demo


#1

Hi Jules,

I have justed tested the latest SVN rev of Juce and ran the juce demo on an ubuntu jaunty distro. The juce demo crashes here:

#0 0x08056e5e in juce::AudioDataConverters::deinterleaveSamples (source=0x9acc828, dest=0xb6f41b6c, numSamples=512, numChannels=2) at ../../src/../../../juce_amalgamated.cpp:24083 #1 0x08252383 in juce::ALSADevice::read (this=0xb6f39380, data=0xb6f41b6c, numSamples=512) at ../../src/../../../juce_amalgamated.cpp:257990 #2 0x08253681 in juce::ALSAThread::run (this=0xb6f41888) at ../../src/../../../juce_amalgamated.cpp:258211 #3 0x08119d80 in juce::Thread::threadEntryPoint (thread=0xb6f41888) at ../../src/../../../juce_amalgamated.cpp:15236

on a null pointer dereference. 2 channels are expected, but the “dst” arrays is NULL for the second channel. I think there is something wrong in AlsaThread::open() , adding an

fprintf(stderr, "minChansIn=%d maxChansIn=%d currentInputChans: %d\n", (int)minChansIn, (int)maxChansIn, (int)currentInputChans.getHighestBit()+1);

displays 2 2 1 , so the channels array “inputChannels” is initialised with only 1 channel, but the AlsaDevice is initialised with 2 channels.

I’m not sure of how to fix that


#2

Ok, I’ve not tried this, but how about adding this code to set more bits in the currentInputChans array:

[code] if (totalNumInputChannels > 0 && inputId.isNotEmpty())
{
inputDevice = new ALSADevice (inputId, true);

        if (inputDevice->error.isNotEmpty())
        {
            error = inputDevice->error;
            deleteAndZero (inputDevice);
            return;
        }

        currentInputChans.setRange (0, minChansIn, true);
        
        if (! inputDevice->setParameters ((unsigned int) sampleRate,
                                          jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
                                          bufferSize))
        {
            error = inputDevice->error;
            deleteAndZero (inputDevice);
            return;
        }
    }

[/code]


#3

it is still crashing as the allocation is done just before, but if I do this:

void open (const BitArray& inputChannels_, // PATCH const BitArray& outputChannels, ... BitArray inputChannels(inputChannels_); // PATCH if (inputChannels.getHighestBit() >= 0) { inputChannels.setRange(0, minChansIn, true); // PATCH for (int i = 0; i <= inputChannels.getHighestBit(); ++i) { inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);

at the beginning of open() it does not crash anymore


#4

Oh yes, it would need to cope with that kind of thing. You could also just write:

void open (BitArray inputChannels, BitArray outputChannels, const double sampleRate_, const int bufferSize_)

So that sorts everything out, does it?


#5

Yes I think it is fine. It works here.


#6

Hi Jules,

I think the fix that was commited in revision r718 is not good.

There is a typo in “currentOutputChans.setRange (0, minChansIn, true);” (should be minChansOut) , and I also think it is not set at the right place (should be done before the juce_calloc calls that allocate room for inputChannelData and outputChannelData).

Here is the fix that I am currently using:

if (outputChannels.getHighestBit() >= 0) { for (int i = 0; i <= jmax(outputChannels.getHighestBit(), minChansOut); ++i) // FIX HERE { outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);


#7

Thanks! Sorry I’ve been a bit slack at testing the linux changes recently!


#8

you should do the same for the input channels btw, I’m still getting the crash:

for (int i = 0; i <= jmax(inputChannels.getHighestBit(), minChansIn); ++i)


#9

Oh, right - thanks, will do!