FileBrowserComponent fails with initialized WildcardFileFilter

I do nothing but create this single header combo as self initializing component.
fileFilter inside FileBrowserComponent looks as not initialized. And hits an error in isFileSuitable(File)
I need a little help.

Exception thrown: read access violation.
this->fileFilter->**** was 0xFFFFFFFFFFFFFFF7.
#include <JuceHeader.h>

class FileBrowserSamples : public juce::Component, public juce::FileBrowserListener
{
public:
    FileBrowserSamples():
        fileBrowser(juce::FileBrowserComponent::openMode |
            juce::FileBrowserComponent::canSelectFiles |
            juce::FileBrowserComponent::canSelectDirectories,
            juce::File::getSpecialLocation(juce::File::userDocumentsDirectory), 
            &fileFilter, NULL)
    {
        fileBrowser.addListener(this);
        addAndMakeVisible(fileBrowser);
    };

    ~FileBrowserSamples() {};
    void fileDoubleClicked(const File& file) override {
        if (onFileDoubleClick != nullptr) {
            onFileDoubleClick(file);
        }
    };

    void resized() override { fileBrowser.setBounds(getLocalBounds()); };

    void paint(juce::Graphics&) override {};
    void selectionChanged() override {};
    void fileClicked(const File& file, const MouseEvent& e) override {};
    void browserRootChanged(const File& newRoot) override {};

    std::function<void(juce::File)> onFileDoubleClick;
    juce::FileBrowserComponent fileBrowser;

private:
    juce::WildcardFileFilter fileFilter = juce::WildcardFileFilter("*.wav;*.aiff", "", "Choose File" );

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(FileBrowserSamples)
};

Your fileBrowser member is being initialised before the fileFilter, since it comes first in your class definition. It needs to be the other way around.

1 Like

OMG! I was going nuts.
Thank you a lot!