[SOLVED] Plugin crashes on load in FLStudio

I’m having an issue where my plugin freezes the host instantly upon being loaded into FLStudio20 on Win10. It works fine in all other hosts I’ve tested. The plugin shows up as “Ok” in the FL plugin manager.

Attaching the VS-debugger to FL reveals nothing, as it still thinks FL is running - so no hard crashes.

Halting the process doesn’t reveal anything either, the call stack will only say “external code” and I can’t see where it froze or got stuck.

I’m using the debug build and copied the .pdb file over to the VST3 folder as well.

Anyone with an idea how to approach this or get better information?

Sounds like a deadlock to me. When you stop in the debugger, did you go through all call stacks of all threads (I remember not knowing that there were more than one back when I got started with all this stuff :smiley: )? Do you use any locks in your code? Then you should start double-checking those sections for possible deadlocks…

1 Like

Wow, thanks you were dead-right!

The multi-thread debugger is well hidden…

Just a question regarding locks: How does this even happen? I’m using the MessageManagerLock, which as far as I understand it is scope based. My code is essentially

void OdinAudioProcessorEditor::updatePitchWheel(float p_value) {
	const MessageManagerLock mmLock;
	m_pitchwheel.setValue(p_value); //m_pitchwheel is a juce::Slider
}

So the actual locking in is somewhere in the Slider class?

Removing the lock triggers some assertion, which warns me not to access the GUI thread from the audio thread. How do I resolve this properly?

Perhaps like this:

Warning: untested code:

void OdinAudioProcessorEditor::updatePitchWheel(float p_value) {
    MessageManager::callAsync ([this, p_value] () {
	    m_pitchwheel.setValue(p_value);
    }
}

This will post a message to the message thread that, when handled (hopefully very soon afterwards) will invoke m_pitchwheel.setValue(p_value); for you.

The only caveat is that you get undefined behaviour if “this” (I assume it’s your plug-in GUI) gets deleted between when the message is posted and when the message thread deletes it. Perhaps you can work around it using SafePointer.

1 Like

I had the same problem with my plugin in Ableton Live when I was using MessageManagerLock.
Like theWaveWarden suggests above, I changed it to using callAsync, and I use the SafePointer like this:

void OdinAudioProcessorEditor::updatePitchWheel(float p_value) {
    auto sp = SafePointer<Component>(this);

    MessageManager::callAsync([p_value, sp, this] {
	    if (sp == nullptr) {
		    return;
	    }
        m_pitchwheel.setValue(p_value);
    }
}
1 Like

Cool thanks for your suggested code. I’m using the snippet provided by nbacklund and it works fine!