diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 17230970..a509e21a 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -329,19 +329,19 @@ static void RackWidget_updateAdjacent(RackWidget *that) { if (m == m2) continue; - math::Vec p2 = m->box.pos.div(RACK_GRID_SIZE).round(); + math::Vec p2 = m2->box.pos.div(RACK_GRID_SIZE).round(); - // Check if m is to the right of m2 + // Check if m is to the left of m2 if (pRight.isEqual(p2)) { - m->module->leftModuleId = m2->module->id; - m2->module->rightModuleId = m->module->id; + m->module->rightModuleId = m2->module->id; + m2->module->leftModuleId = m->module->id; found = true; break; } } if (!found) { - m->module->leftModuleId = -1; + m->module->rightModuleId = -1; } } } diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index fb6952f3..6de88eda 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -267,6 +267,11 @@ static void Engine_step(Engine *that) { for (Cable *cable : that->internal->cables) { cable->step(); } + // Swap messages of all modules + for (Module *module : that->internal->modules) { + std::swap(module->leftProducerMessage, module->leftConsumerMessage); + std::swap(module->rightProducerMessage, module->rightConsumerMessage); + } } static void Engine_updateAdjacent(Engine *that, Module *m) {