MidiInput::getDevices() leaks MessageManager?


#1

Hi,

Using only the MidiInput::getDevices() static method inside a console application gives me a leaked object (of class MessageManager) assert failure.

#include "../JuceLibraryCode/JuceHeader.h"
//==============================================================================
int main (int argc, char* argv[])
{

    for (String device : MidiInput::getDevices())
    {
    Logger::outputDebugString(device);
    }

    return 0;
}

Am I missing something?

Thanks in advance for your help.

Cheers,

Mathieu


#2

MessageManager is a singleton that gets constructed by its first user. In the case of a GUI app, the lifetime of MessageManager would be bound to the lifetime of your class that derives from JUCEApplication or JUCEApplicationBase, and it would get properly destructed on program end. For console apps, you need to construct a ScopedJuceInitialiser_GUI that will manage the lifetime of the MessageManager for you. So add the following statement at the beginning of your main function and everything should be cleaned-up properly:

ScopedJuceInitialiser_GUI scopedJuceGui;