Help with expansion module code (crashing)

I could use a second set of eyes. My code is crashing when I place my new expansion module next to my “mother” module. I’m suspecting that I didn’t declare my buffer properly, although I’m following Andrew’s example here verbatim. Any suggestions?

struct GrainEngineMK2Expander : Module
{
  GrainEngineMK2Expander() {
  }

  void process(const ProcessArgs &args) override {
    if (rightExpander.module && rightExpander.module->model == modelGrainEngineMK2)
    {
      // Send a message to the GrainEngineMK2 on the right
      float *buffer = (float*) rightExpander.module->leftExpander.producerMessage;
      buffer[0] = 1.f;
    }
    else
    {
	// No Grain Engine MK2 to the right, so do nothing
    }
  }
};

Mother module code:

 void processExpander()
  {
    if (leftExpander.module && leftExpander.module->model == modelGrainEngineMK2) {
      leftExpander.module->rightExpander.messageFlipRequested = true;
    }
  }
1 Like

Are you initializing leftExpander.consumerMessage in the „mother“ module?

Also leftExpander.module->rightExpander.messageFlipRequested = true looks incorrect, this should be leftExpander.messageFlipRequested = true

No, I was a little confused about that. I don’t think that I am initializing leftExpander.consumerMessage in the mother module. Could you show me an example of how to do that? I tried the following, but it’s still crashing:

struct GrainEngineMK2Expander : Module
{
  float rightMessages[2][8] = {};

  GrainEngineMK2Expander() {
    rightExpander.producerMessage = rightMessages[0];
    rightExpander.consumerMessage = rightMessages[1];
  }

  void process(const ProcessArgs &args) override {
    if (rightExpander.module && rightExpander.module->model == modelGrainEngineMK2) {
      // Send a message to the GrainEngineMK2 on the right
      float *buffer = (float*) rightExpander.module->leftExpander.producerMessage;
      buffer[0] = 1.f;
    }
    else {
			// No Grain Engine MK2 to the right, so do nothing
    }
  }
};

I think I know why, but I’m a bit lost. rightExpander.producerMessage = rightMessages[0]; sets the producerMessage in the expansion module’s rightExpander object. But nothing sets the producerMessage or consumerMessage pointers in the mother module.

Where and how would that be done? Would I need to declare an array like leftMessages in the mother module and set its leftExpander.producerMessage and leftExpender.consumerMessage pointers to the leftMessages[0] and [1] float arrays?

Thanks!

You should move

    rightExpander.producerMessage = rightMessages[0];
    rightExpander.consumerMessage = rightMessages[1];

to the “mother” module, but using leftExpander struct instead. If you set leftExpander.messageFlipRequested = true there you should be not far from a working prototype.

It is a bit confusing at first. Just keep in mind that only one module is owner of the data and the expander accesses this data of the module next to it if present.

Ah, yes! That seems to have worked. At least, it’s not crashing now, so I can move on to the interesting part of the project. Thanks Ben!

You’re welcome :slight_smile:

1 Like