Error looping thru user settings XmlElement

Hi,

I am getting very strange exception I don’t understand.

I have foldersCollection object (component), and I can successfully call addFolder inside a loop where I iterate thru my user settings (XmlElements).

My foldersCollection has a callback, and there I use exactly the same loop and want to do some code inside. But! it breaks at the point where I try to call a method of my XmlElement.

auto fxml = getAppProperties().getUserSettings()->getXmlValue("VSTFolders");
        if (fxml == nullptr){
            getAppProperties().getUserSettings()->getXmlValue("VSTFolders").reset(new XmlElement("folders"));
        }

       // this works fine:
        for (auto *f : fxml->getChildIterator()){
            foldersCollection->addFolder(f->getText().toStdString());
        }

        // if I pass a pointer of Xml, then I get error. Even if I don't pass it, but load settings again... 
        foldersCollection->onFolderRemoved = [&fxml](std::string path){
            const MessageManagerLock l;
            // fxml = getAppProperties().getUserSettings()->getXmlValue("VSTFolders"); -- does not help;
            for (auto *f : fxml->getChildIterator()){
                auto t = f->getAllSubText(); //error = read memory from 0xcccccccccccccccc failed (0 of 8 bytes read)
            }
        };

From the screen shot, it looks like this code is in the constructor. And thus the lifetime of fxml is only within the constructor. So, your onFolderRemoved callback happens after fxml has gone out of scope, and thus the error. It seems that you would want fxml to be a member of the class so that it’s lifetime follows the lifetime of the class.