diff --git a/compile.mk b/compile.mk index 42c45335..18e25262 100644 --- a/compile.mk +++ b/compile.mk @@ -10,7 +10,7 @@ OBJCOPY ?= objcopy FLAGS += -MMD -MP FLAGS += -g # Optimization -FLAGS += -O3 -march=nocona -ffast-math -fno-finite-math-only +FLAGS += -O0 -march=nocona -ffast-math -fno-finite-math-only FLAGS += -Wall -Wextra -Wno-unused-parameter ifneq ($(ARCH), mac) diff --git a/include/app/RackWidget.hpp b/include/app/RackWidget.hpp index f39df7b3..40569494 100644 --- a/include/app/RackWidget.hpp +++ b/include/app/RackWidget.hpp @@ -42,6 +42,7 @@ struct RackWidget : OpaqueWidget { void pastePresetClipboard(); void addModule(ModuleWidget *m); + void addModuleAtMouse(ModuleWidget *m); /** Removes the module and transfers ownership to the caller */ void deleteModule(ModuleWidget *m); void cloneModule(ModuleWidget *m); diff --git a/include/app/Scene.hpp b/include/app/Scene.hpp index 47597741..f8ad45f2 100644 --- a/include/app/Scene.hpp +++ b/include/app/Scene.hpp @@ -11,10 +11,9 @@ namespace rack { struct Scene : OpaqueWidget { + // Convenience variables for accessing important widgets ScrollWidget *scrollWidget; ZoomWidget *zoomWidget; - - // Convenience variables for accessing important widgets RackWidget *rackWidget; Toolbar *toolbar; @@ -25,6 +24,7 @@ struct Scene : OpaqueWidget { std::string latestVersion; Scene(); + ~Scene(); void step() override; void draw(NVGcontext *vg) override; void onHoverKey(const event::HoverKey &e) override; diff --git a/src/app/ModuleBrowser.cpp b/src/app/ModuleBrowser.cpp index 26fabff6..0b4e07fe 100644 --- a/src/app/ModuleBrowser.cpp +++ b/src/app/ModuleBrowser.cpp @@ -33,10 +33,7 @@ struct ModuleWidgetWrapper : ObstructWidget { // Create module ModuleWidget *moduleWidget = model->createModuleWidget(); assert(moduleWidget); - context()->scene->rackWidget->addModule(moduleWidget); - // Move module nearest to the mouse position - moduleWidget->box.pos = context()->scene->rackWidget->lastMousePos.minus(moduleWidget->box.size.div(2)); - context()->scene->rackWidget->requestModuleBoxNearest(moduleWidget, moduleWidget->box); + context()->scene->rackWidget->addModuleAtMouse(moduleWidget); // Close Module Browser MenuOverlay *menuOverlay = getAncestorOfType(); menuOverlay->requestedDelete = true; @@ -62,7 +59,7 @@ struct ModuleBrowser : OpaqueWidget { ModuleWidget *moduleWidget = model->createModuleWidgetNull(); zoomWidget->addChild(moduleWidget); wrapper->box.size = moduleWidget->box.size.mult(zoomWidget->zoom); - p = wrapper->box.getTopRight(); + p = wrapper->box.getTopRight().plus(math::Vec(20, 0)); } } } diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index c777f53c..3fb566ab 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -22,8 +22,11 @@ ModuleWidget::ModuleWidget(Module *module) { } ModuleWidget::~ModuleWidget() { - // Make sure WireWidget destructors are called *before* removing `module` from the rack. - disconnect(); + // HACK + // If we try to disconnect wires in the Module Browser (e.g. when Rack is closed while the Module Browser is open), context()->scene->rackWidget will be an invalid pointer. + // So only attempt to disconnect if the module is not NULL. + if (module) + disconnect(); // Remove and delete the Module instance if (module) { context()->engine->removeModule(module); diff --git a/src/app/PortWidget.cpp b/src/app/PortWidget.cpp index af0455d6..d266a847 100644 --- a/src/app/PortWidget.cpp +++ b/src/app/PortWidget.cpp @@ -25,7 +25,10 @@ PortWidget::PortWidget() { PortWidget::~PortWidget() { // plugLight is not a child and is thus owned by the PortWidget, so we need to delete it here delete plugLight; - context()->scene->rackWidget->wireContainer->removeAllWires(this); + // HACK + // See ModuleWidget::~ModuleWidget for description + if (module) + context()->scene->rackWidget->wireContainer->removeAllWires(this); } void PortWidget::step() { diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 569fe629..167f2e32 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -458,6 +458,13 @@ void RackWidget::addModule(ModuleWidget *m) { moduleContainer->addChild(m); } +void RackWidget::addModuleAtMouse(ModuleWidget *m) { + addModule(m); + // Move module nearest to the mouse position + m->box.pos = lastMousePos.minus(m->box.size.div(2)); + requestModuleBoxNearest(m, m->box); +} + void RackWidget::deleteModule(ModuleWidget *m) { moduleContainer->removeChild(m); } diff --git a/src/app/Scene.cpp b/src/app/Scene.cpp index bc78e63d..60955171 100644 --- a/src/app/Scene.cpp +++ b/src/app/Scene.cpp @@ -28,6 +28,9 @@ Scene::Scene() { scrollWidget->box.pos.y = toolbar->box.size.y; } +Scene::~Scene() { +} + void Scene::step() { // Resize owned descendants toolbar->box.size.x = box.size.x;