AudioDeviceSelectorComponent's Test button causes crash (iMac running Windows)!


#1

I'm trying to get the Audio Settings to come up in their own window/dialog-box.

I create a fresh "audio application", and add the following code at the start:


class AudioSettings 
{
public:
    static AudioDeviceManager& getSharedAudioDeviceManager() {
        static AudioDeviceManager* sharedAudioDeviceManager;
        if (sharedAudioDeviceManager == nullptr) {
            sharedAudioDeviceManager = new AudioDeviceManager();
            sharedAudioDeviceManager->initialise(2, 2, 0, true, String(), 0);
        }
        return *sharedAudioDeviceManager;
    }
    static void launch() {
        auto& deviceManager = getSharedAudioDeviceManager();
        // Present an audio settings dialog box.
        AudioDeviceSelectorComponent* settings = new AudioDeviceSelectorComponent(
            deviceManager,
            0, 0, 1, 2,
            true, // showMidiInputOptions
            true, // showMidiOutputSelector
            true, // showChannelsAsStereoPairs
            true  // hideAdvancedOptions
            );
        settings->setSize(600, 400);
        DialogWindow::LaunchOptions options;
        options.content.setOwned(settings);
        options.dialogTitle = "Audio Settings";
        options.dialogBackgroundColour = Colours::lightgrey;
        options.escapeKeyTriggersCloseButton = true;
        options.useNativeTitleBar = true;
        options.resizable = true;
        
        DialogWindow* dw = options.launchAsync();
        dw->centreWithSize(450, 350);
    }
};
class MainContentComponent   : public AudioAppComponent
{
public:
    MainContentComponent() {
        setSize (800, 600);
        setAudioChannels (2, 2);
        AudioSettings::launch();
    }

When I run this, the dialog shows:

Pressing the "Test" button correctly sounds, but then it crashes with:

Exception thrown: read access violation.
juce::Array<juce::AudioIODeviceCallback *,juce::DummyCriticalSection,0>::getUnchecked(...)-> was 0x1.
If there is a handler for this exception, the program may be safely continued.

 

What's going wrong?

π


#2

Hm. I tested the exact code you posted here, on Xcode 7 and Visual Studio 2015, and I don't get any kind of crash.

Maybe it's something else? Something with your audio device driver? Does it also crash if you use the built-in output?


#3

This seems like a bug that was previously reported and what might be fixed if you update your Juce to the latest one.


#4

Yes! That's the problem! I was still using modules from the old JUCE.

That's careless on my part, I thought I was using the latest JUCE, but I wasn't. Sorry for the noise!

Thanks Xenakios!


#5

Yes, I am suspecting this as well, because I cannot reproduce your situation...

Does this only happen with a particular device? What if you select the default audio I/O? What if you connect some other sound card?


#6

you should use a SharedResourcePointer instead of a static.