v2 - Assertion failed: threadContext, file src/context.cpp, line 41

hi,

when I access to APP->engine->getSampleRate() within a thread, i got this assertion:

Assertion failed: threadContext, file src/context.cpp, line 41

do you know why this happens and how to resolve it?

i basically create a new thread from a v2 module with mThread = std::thread(&AsyncProcess::task, this);

Do you really need to get the Sample Rate from the thread ?

maybe you have sample rate at the start, and RARELY someone changes the rate of the system
so you get and “changeSampleRate” (or something like this)

you in the main module store the rate

float m_sr = 44100.0;

in the constructor m_sr = APP->engine->getSampleRate()

and change it in the event: m_sr = APP->engine->getSampleRate()

in your worker thread (assuming this is a pointer to your module

you’ll get the SR with

this->m_sr

1 Like

You can try Antonio’s suggestion, but if you want to get the context thing working, I would suggest looking at an example here:

done, and it magically now works. thanks antonio.

its ok as “temp” solution… but why this? isn’t “dangerous” have this behaviour on abi?