Error when in select Midi source

Hi, I wrote this code, but every time I change item selected (not the first time I select one) in my comboBox it gives me this error “JUCE Message Thread (1): EXC_BAD_ACCESS (code=1, address=0x10)” in line 918 of doc “atomic”:

midiInputList1.onChange = [this] {
    for (int i = 0; i<midiSources.size(); i++)
    {
        if (selectedInFilteredDevice.get() != nullptr) { selectedInFilteredDevice->stop(); }
        
        if (midiInputList1.getSelectedItemIndex() == i)
        {
            selectedInFilteredDevice.reset(MidiInput::openDevice(i, this).get());
            selectedInFilteredDevice->start();
        }
    }
};

does anyone have an idea of why?

Is there more of a stack trace available? and/or have you stepped through it with the debugger to determine which of those lines it is crashing in?

1 Like

Hi thank you for you’re reply.
In that code error rise up in this line:

selectedInFilteredDevice.reset(MidiInput::openDevice(i, this).get());

And there is only one stack trace :slight_smile:

Thank you again for help

This will delete the object that you then go on to use.

Honestly, if you don’t know how to use std::unique_ptr correctly, then C++ is always going to be a struggle! There are loads of really good, well-written books and articles explaining it, you really should take the time to properly nail your understanding of it.

1 Like

Thank you, solved :slight_smile: