Thread error in filter

Im making a FIR filter and it works ok but after a while of using it I get thrown a thread error

void Component::internalRepaintUnchecked (Rectangle< int > area, bool isEntireComponent)

{

// if component methods are being called from threads other than the message

// thread, you’ll need to use a MessageManagerLock object to make sure it’s thread-safe.

JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED

any help on this? Thanks.

Wondering why your Filter has anything to do with a repaint of a component?

Are you calling paint / GUI methods directly from your audio thread? :slight_smile:

If so, that could be the problem. The Audio thread shouldn’t call anything that paints something or updates a component. It should just filter your audio-stream ( in your case).

Would you mind posting the corresponding call stack?

Yeah let me try to find it really quick and Ill post RN

void MainComponent::getNextAudioBlock ( const juce::AudioSourceChannelInfo& bufferToFill)
{
bufferToFill.clearActiveBufferRegion();
transport.getNextAudioBlock(bufferToFill);
transport.setGain(mainVol.getValue() * 0.025f);
juce::dsp::AudioBlock< float > block (*bufferToFill.buffer);
updateFilter();
process(juce::dsp::ProcessContextReplacing< float > (block));
}

void MainComponent::updateFilter()
{
rate_Knob.setRange(100.0f, 8500.0f);
depth_Knob.setRange(1, 4.0f);

int menuChoice = menu.getSelectedId();
int cutOff = rate_Knob.getValue();
int rez = depth_Knob.getValue();

switch (menuChoice) {
    case 1:
        state_VarFilter.state->type = juce::dsp::StateVariableFilter::Parameters<float>::Type::bandPass;
        break;
    case 2:
        state_VarFilter.state->type = juce::dsp::StateVariableFilter::Parameters<float>::Type::highPass;
    case 3:
        state_VarFilter.state->type = juce::dsp::StateVariableFilter::Parameters<float>::Type::lowPass;
    default:
        break;
}
state_VarFilter.state->setCutOffFrequency(currentSampleRate, cutOff, rez);

}

void MainComponent::process(juce::dsp::ProcessContextReplacing< float > context)
{
updateFilter();
state_VarFilter.process(context);
}

void MainComponent::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
{
transport.prepareToPlay(samplesPerBlockExpected, sampleRate);
juce::dsp::ProcessSpec spec;
spec.sampleRate = sampleRate;
spec.maximumBlockSize = samplesPerBlockExpected;
spec.numChannels = 2;
state_VarFilter.reset();
updateFilter();
state_VarFilter.prepare(spec);
}

JUCE Message Thread (1) Queue : com.apple.main-thread (serial)#0 0x00007fff526c8958 in -[CUIPSDGradientEvaluator

_smoothedInterpolationOfLocation:betweenLower:upper:scaledMidpoint:] ()#28

0x00007fff3604bac3 in -[NSWindow initWithContentRect:styleMask:backing:defer:] ()
#29 0x0000000100695889 in juce::NSViewComponentPeer::NSViewComponentPeer(juce::Component&, int, NSView*) at /Users/josephescamilla/JUCE/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm:129

#30 0x00000001005fdc6b in juce::NSViewComponentPeer::NSViewComponentPeer(juce::Component&, int, NSView*) at /Users/josephescamilla/JUCE/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm:89

#31 0x00000001005fdc08 in juce::Component::createNewPeer(int, void*) at /Users/josephescamilla/JUCE/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm:2244

#32 0x00000001005163c8 in juce::Component::addToDesktop(int, void*) at /Users/josephescamilla/JUCE/modules/juce_gui_basics/components/juce_Component.cpp:671

#33 0x00000001005eca73 in juce::TopLevelWindow::recreateDesktopWindow() at /Users/josephescamilla/JUCE/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp:251

#34 0x0000000100549e18 in juce::ResizableWindow::setResizable(bool, bool) at /Users/josephescamilla/JUCE/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp:302

#35 0x0000000100003ede in NewProjectApplication::MainWindow::MainWindow(juce::String) at /Users/josephescamilla/JUCE/DevOps/NewProject/Source/Main.cpp:73

#36 0x0000000100003df5 in NewProjectApplication::MainWindow::MainWindow(juce::String) at /Users/josephescamilla/JUCE/DevOps/NewProject/Source/Main.cpp:66

#37 0x000000010000396b in NewProjectApplication::initialise(juce::String const&) at /Users/josephescamilla/JUCE/DevOps/NewProject/Source/Main.cpp:28

#38 0x00000001003eedce in juce::JUCEApplicationBase::initialiseApp() at /Users/josephescamilla/JUCE/modules/juce_events/messages/juce_ApplicationBase.cpp:297

#39 0x00000001005f47e8 in juce::JUCEApplication::initialiseApp() at /Users/josephescamilla/JUCE/modules/juce_gui_basics/application/juce_Application.cpp:92

#40 0x00000001003eeb51 in juce::JUCEApplicationBase::main() at /Users/josephescamilla/JUCE/modules/juce_events/messages/juce_ApplicationBase.cpp:256

#41 0x00000001003ee9cc in juce::JUCEApplicationBase::main(int, char const**) at /Users/josephescamilla/JUCE/modules/juce_events/messages/juce_ApplicationBase.cpp:240

#42 0x00000001000037a3 in main at /Users/josephescamilla/JUCE/DevOps/NewProject/Source/Main.cpp:105

#43 0x00007fff72c9acc9 in start ()

#0 0x00007fff72ddd4ce in __workq_kernreturn ()

#0 0x00007fff72ddd4ce in __workq_kernreturn ()

#2 0x00000001022b049b in start_wqthread ()

#0 0x00007fff72ddd4ce in __workq_kernreturn ()

#0 0x00007fff72ddd4ce in __workq_kernreturn ()

#0 0x00007fff72ddbe36 in semaphore_wait_trap ()

#0 0x00007fff72ddbe4e in semaphore_timedwait_trap ()
#5 0x00000001022b04af in thread_start ()

USB Audio CODEC (9)

#0 0x000000010051cade in juce::Component::internalRepaintUnchecked(juce::Rectangle, bool) at /Users/josephescamilla/JUCE/modules/juce_gui_basics/components/juce_Component.cpp:1857

#1 0x0000000100515a0a in juce::Component::repaint() at /Users/josephescamilla/JUCE/modules/juce_gui_basics/components/juce_Component.cpp:1826

#2 0x00000001005c2771 in juce::Slider::Pimpl::setValue(double, juce::NotificationType) at /Users/josephescamilla/JUCE/modules/juce_gui_basics/widgets/juce_Slider.cpp:200

#3 0x000000010065adb2 in juce::Slider::Pimpl::updateRange() at /Users/josephescamilla/JUCE/modules/juce_gui_basics/widgets/juce_Slider.cpp:137

#4 0x00000001005c20c9 in juce::Slider::Pimpl::setRange(double, double, double) at /Users/josephescamilla/JUCE/modules/juce_gui_basics/widgets/juce_Slider.cpp:152

#5 0x00000001005b2ef4 in juce::Slider::setRange(double, double, double) at /Users/josephescamilla/JUCE/modules/juce_gui_basics/widgets/juce_Slider.cpp:1507

#6 0x0000000100010b32 in MainComponent::updateFilter() at /Users/josephescamilla/JUCE/DevOps/NewProject/Source/MainComponent.cpp:477

#7 0x0000000100010eed in MainComponent::getNextAudioBlock(juce::AudioSourceChannelInfo const&) at /Users/josephescamilla/JUCE/DevOps/NewProject/Source/MainComponent.cpp:471

#8 0x00000001000b8b48 in juce::AudioSourcePlayer::audioDeviceIOCallback(float const**, int, float**, int, int) at /Users/josephescamilla/JUCE/modules/juce_audio_devices/sources/juce_AudioSourcePlayer.cpp:138

#9 0x00000001000b4823 in juce::AudioDeviceManager::audioDeviceIOCallbackInt(float const**, int, float**, int, int) at /Users/josephescamilla/JUCE/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp:824

#10 0x00000001000be33f in juce::AudioDeviceManager::CallbackHandler::audioDeviceIOCallback(float const**, int, float**, int, int) at /Users/josephescamilla/JUCE/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp:54

#11 0x00000001000cab75 in juce::CoreAudioClasses::AudioIODeviceCombiner::run() at /Users/josephescamilla/JUCE/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp:1605

#12 0x00000001002a5e44 in juce::thread::threadEntryPoint() at /Users/josephescamilla/JUCE/modules/juce_core/threads/juce_Thread.cpp:96

#13 0x00000001002a62f8 in juce::juce_threadEntryPoint(void*) at /Users/josephescamilla/JUCE/modules/juce_core/threads/juce_Thread.cpp:118

#14 0x00000001002cfe49 in juce::threadEntryProc(void*) at /Users/josephescamilla/JUCE/modules/juce_core/native/juce_posix_SharedCode.h:838

#15 0x00000001022b4c65 in _pthread_start ()

#16 0x00000001022b04af in thread_start ()

com.apple.audio.IOThread.client (10)
#0 0x00007fff72ddbdfa in mach_msg_trap ()
#5 0x00000001022b04af in thread_start ()
com.apple.audio.IOThread.client (11)
#0 0x00007fff72ddbdfa in mach_msg_trap ()
#5 0x00000001022b04af in thread_start ()

(lldb) po [NSThread callStackSymbols]

<_NSCallStackArray 0x600000c98840>(
0 ??? 0x000000011455b190 0x0 + 4636127632,
1 NewProject 0x0000000100003770 main + 0,
2 CoreAudio 0x00007fff383a36c5 ___ZN19HALC_ProxyIOContextC2Ejj_block_invoke + 546,
3 CoreAudio 0x00007fff384d7c22 _ZN13HALB_IOThread5EntryEPv + 72,
4 libsystem_pthread.dylib 0x00000001022b4c65 _pthread_start + 148,
5 libsystem_pthread.dylib 0x00000001022b04af thread_start + 15
)

(lldb)

The only update that has anything to do with that would be in my updateFilter method where I tie slider values to variables that are input parameters for the filter itself.

First of all, please put a line of ``` above and below your code and call stack sections, this will make the forum software format them differently to make them better readable. You can edit your posts with the pen icon you find below each of your posts.

Then, I think I see the location of the error somewhere around here:

getNextAduioBlock calls updateFilter (we see that in the code snippet you provided above as well). Then in updateFilter you call setRange on some slider, which is a big no-go. This might trigger this slider to change its graphical appearance, so this might lead to re-drawing the slider. Drawning should only ever be handled from the MessageThread, looking a bit down the call stack we see that we are on the audio io thread, which is a high priority system call, only designed to process audio and nothing else. So you need to change that design. But anyway, what’s the point on changing the slider range at audio callback rate? Is it possible that updateFilter performs actions that usually should be only performed once in the prepare call and not several times per second on the audio callback?

Dude your a hoss,
thanks its working better with less distortion !

I’ll add those marks above my code from now on.