Juce Message Thread (1): EXC_BAD_ACCESS

I have that error: Juce Message Thread (1): EXC_BAD_ACCESS (code=1, address=0x1c8)
But xCode compiles my code with no error. Such error happens only when I open compiled app. I am not sure why but I’ve seen somewhere and my intuition tells me that to repair that I need to use:

if ((mojVoice = dynamic_cast<WojtekSynthVoice*>(mojSynt.getVoice(i))))

but that solution works in processBlock function. But I need to set up sample rate for my SynthesiserVoice, so in my opinion it would be better to set it in prepareToPlay. But I am not sure how to use dynamic_cast. Could anyone help? Thanks in advance.

EXC_BAD_ACCESS means that whatever address you’re trying to access is invalid. So, use your debugger to see what variable in the current scope is nullptr. Also, go read en.cppreference.com for how to use dynamic_cast