I have added the following AudioSettings.h to my project, so that I can launch an audio device manager window:
#include "../JuceLibraryCode/JuceHeader.h"
class AudioSettings
{
SharedResourcePointer<AudioDeviceManager> sharedAudioDeviceManager;
public:
//static AudioDeviceManager& getSharedAudioDeviceManager()
//{
// static AudioDeviceManager* sharedAudioDeviceManager;
// if (sharedAudioDeviceManager == nullptr)
// {
// sharedAudioDeviceManager = new AudioDeviceManager();
// sharedAudioDeviceManager->initialise(2, 2, 0, true, String(), 0);
// }
// return *sharedAudioDeviceManager;
//}
ScopedPointer<AudioDeviceSelectorComponent> settings;
ScopedPointer<DialogWindow> dw;
void launch()
{
//auto& deviceManager = getSharedAudioDeviceManager();
sharedAudioDeviceManager->initialise(
0, // numInputChannelsNeeded
2, // numOutputChannelsNeeded
nullptr, // XML
true, // selectDefaultDeviceOnFailure
String(), // preferredDefaultDeviceName
0 // preferredSetupOptions
);
// Present an audio settings dialog box.
settings = new AudioDeviceSelectorComponent(*sharedAudioDeviceManager,
0, 0, // min/max inputs
2, 2, // min/max outputs
true, // showMidiInputOptions
true, // showMidiOutputSelector
true, // showChannelsAsStereoPairs
true // hideAdvancedOptions
);
settings->setSize(640, 480);
DialogWindow::LaunchOptions options;
options.content.setOwned(settings);
options.dialogTitle = "Audio Settings";
options.dialogBackgroundColour = Colours::lightgrey;
options.escapeKeyTriggersCloseButton = true;
options.useNativeTitleBar = true;
options.resizable = true;
dw = options.launchAsync();
dw->centreWithSize(450, 250);
}
};
However when I quit my app, I get an exception here:
#ifndef JUCE_CONTAINERDELETEPOLICY_H_INCLUDED
#define JUCE_CONTAINERDELETEPOLICY_H_INCLUDED
//==============================================================================
/**
Used by container classes as an indirect way to delete an object of a
particular type.
The generic implementation of this class simply calls 'delete', but you can
create a specialised version of it for a particular class if you need to
delete that type of object in a more appropriate way.
@see ScopedPointer, OwnedArray
*/
template <typename ObjectType>
struct ContainerDeletePolicy
{
static void destroy (ObjectType* object)
{
// If the line below triggers a compiler error, it means that you are using
// an incomplete type for ObjectType (for example, a type that is declared
// but not defined). This is a problem because then the following delete is
// undefined behaviour. The purpose of the sizeof is to capture this situation.
// If this was caused by a ScopedPointer to a forward-declared type, move the
// implementation of all methods trying to use the ScopedPointer (e.g. the destructor
// of the class owning it) into cpp files where they can see to the definition
// of ObjectType. This should fix the error.
ignoreUnused (sizeof (ObjectType));
delete object; // <-- Exception thrown at 0x00D8C2A8 in Trainer.exe: 0xC0000005: Access violation reading location 0xDDDDDDDD.
}
};
#endif // JUCE_CONTAINERDELETEPOLICY_H_INCLUDED
Here is the main component:
#include "AudioSettings.h"
class MainContentComponent : public AudioAppComponent, private Timer
{
private:
ScopedPointer<AudioSettings> settings;
public:
MainContentComponent()
{
:
settings = new AudioSettings(); // <-- if I remove these, it quits ok!
settings->launch();
~MainContentComponent()
{
shutdownAudio(); // <-- error callstack includes here!
}
I've read the comment associated with the exception, and I think my code avoids the case outlined: my AudioSettings is defined before I use ScopedPointer<AudioSettings>.
What is going wrong?
π
