AudioProcessorGraph crashes when changing processing settings

Hello everyone!

So I just built a plugin that emulates a modular synth. To do so, I used an AudioProcessorGraph that holds and manages different AudioProcessor modules.
When I run the plugin, if I try to change, let’s say, the sample rate, I get an assertionFault when the graph tries to rebuild itself. It calls the addNode() method and hits here:

Node::Ptr addNode (std::unique_ptr<AudioProcessor> newProcessor, const NodeID nodeID)
{
    if (newProcessor == nullptr)
    {
        // Cannot add a null audio processor!
        jassertfalse;
        return {};
    }

I get the same exact error if I try to change the output ports. My audio interface has OUT 1-2 and OUT 3-4. if I switch from one another I still get the same assertionFault.
How could I prevent this to happen?
Thanks in advance

-Giacomo

Edit: I am having a look at the stack calls. It seems that When the sequence is rebuilding, and the addNode() method is called, the nodeID that is used doesn’t relate to any processor in the graph. I have 4 nodes and the nodeID is 5, so of course the related processor results to be nullptr…