I’m working at this module randLoops8
During tests I noticed that when Rack autosaves the patch one of the outputs stops to work, so I tried to deeply debug it and found that, when autosave occurs, one not involved array is set to zero.
this is the dataToJson():
json_t* dataToJson() override {
json_t* rootJ = json_object();
json_object_set_new(rootJ, "InitStart", json_boolean(initStart));
json_object_set_new(rootJ, "dontAdvanceSetting", json_boolean(dontAdvanceSetting));
json_object_set_new(rootJ, "polyChans", json_integer(polyChans));
json_object_set_new(rootJ, "bitResolution", json_integer(bitResolution));
json_object_set_new(rootJ, "progression", json_integer(progression));
json_object_set_new(rootJ, "outType", json_integer(outType));
for (int t = 0; t < 8; t++)
sequence_to_saveRegister(t); // THIS COMMENTED LET bitResTable DONT GO TO ZERO
for (int t = 0; t < 8; t++) {
json_t *track_json_array = json_array();
for (int tempStep = 0; tempStep < 16; tempStep++) {
json_array_append_new(track_json_array, json_integer(saveRegister[t][tempStep]));
}
json_object_set_new(rootJ, ("sr"+to_string(t)).c_str(), track_json_array);
}
return rootJ;
}
this bitResTable is the array that goes to zero:
int bitResTable[2] = {8, 16};
int tempRegister[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int tempSaveRegister[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
this happens also if I declare it as const.
if I comment sequence_to_saveRegister() call it doesn’t happen.
This is the code:
void inline sequence_to_saveRegister(int t) {
int cursor = startingStep[t];
int wSteps = int(params[LENGTH_PARAM+t].getValue());
for (int i = 0; i <= wSteps; i++) {
tempSaveRegister[i] = shiftRegister[t][cursor];
cursor++;
if (cursor >= 16)
cursor = 0;
}
int fillCursor = 0;
for (int i = wSteps; i < 16; i++) {
tempSaveRegister[i] = tempSaveRegister[fillCursor];
fillCursor++;
if (fillCursor >= wSteps)
fillCursor = 0;
}
for (int i = 0; i < 16; i++)
saveRegister[t][i] = tempSaveRegister[i];
}
but if I replace that tempSaveRegister with tempRegister everything works fine. But I’m using tempRegister elsewhere, so I imagine it’s not thread-safe.
Any ideas?