Browse Source

Add hack when disconnecting ModuleWidgets with NULL Module

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
2e4faa4a10
8 changed files with 25 additions and 11 deletions
  1. +1
    -1
      compile.mk
  2. +1
    -0
      include/app/RackWidget.hpp
  3. +2
    -2
      include/app/Scene.hpp
  4. +2
    -5
      src/app/ModuleBrowser.cpp
  5. +5
    -2
      src/app/ModuleWidget.cpp
  6. +4
    -1
      src/app/PortWidget.cpp
  7. +7
    -0
      src/app/RackWidget.cpp
  8. +3
    -0
      src/app/Scene.cpp

+ 1
- 1
compile.mk View File

@@ -10,7 +10,7 @@ OBJCOPY ?= objcopy
FLAGS += -MMD -MP FLAGS += -MMD -MP
FLAGS += -g FLAGS += -g
# Optimization # 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 FLAGS += -Wall -Wextra -Wno-unused-parameter


ifneq ($(ARCH), mac) ifneq ($(ARCH), mac)


+ 1
- 0
include/app/RackWidget.hpp View File

@@ -42,6 +42,7 @@ struct RackWidget : OpaqueWidget {
void pastePresetClipboard(); void pastePresetClipboard();


void addModule(ModuleWidget *m); void addModule(ModuleWidget *m);
void addModuleAtMouse(ModuleWidget *m);
/** Removes the module and transfers ownership to the caller */ /** Removes the module and transfers ownership to the caller */
void deleteModule(ModuleWidget *m); void deleteModule(ModuleWidget *m);
void cloneModule(ModuleWidget *m); void cloneModule(ModuleWidget *m);


+ 2
- 2
include/app/Scene.hpp View File

@@ -11,10 +11,9 @@ namespace rack {




struct Scene : OpaqueWidget { struct Scene : OpaqueWidget {
// Convenience variables for accessing important widgets
ScrollWidget *scrollWidget; ScrollWidget *scrollWidget;
ZoomWidget *zoomWidget; ZoomWidget *zoomWidget;

// Convenience variables for accessing important widgets
RackWidget *rackWidget; RackWidget *rackWidget;
Toolbar *toolbar; Toolbar *toolbar;


@@ -25,6 +24,7 @@ struct Scene : OpaqueWidget {
std::string latestVersion; std::string latestVersion;


Scene(); Scene();
~Scene();
void step() override; void step() override;
void draw(NVGcontext *vg) override; void draw(NVGcontext *vg) override;
void onHoverKey(const event::HoverKey &e) override; void onHoverKey(const event::HoverKey &e) override;


+ 2
- 5
src/app/ModuleBrowser.cpp View File

@@ -33,10 +33,7 @@ struct ModuleWidgetWrapper : ObstructWidget {
// Create module // Create module
ModuleWidget *moduleWidget = model->createModuleWidget(); ModuleWidget *moduleWidget = model->createModuleWidget();
assert(moduleWidget); 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 // Close Module Browser
MenuOverlay *menuOverlay = getAncestorOfType<MenuOverlay>(); MenuOverlay *menuOverlay = getAncestorOfType<MenuOverlay>();
menuOverlay->requestedDelete = true; menuOverlay->requestedDelete = true;
@@ -62,7 +59,7 @@ struct ModuleBrowser : OpaqueWidget {
ModuleWidget *moduleWidget = model->createModuleWidgetNull(); ModuleWidget *moduleWidget = model->createModuleWidgetNull();
zoomWidget->addChild(moduleWidget); zoomWidget->addChild(moduleWidget);
wrapper->box.size = moduleWidget->box.size.mult(zoomWidget->zoom); wrapper->box.size = moduleWidget->box.size.mult(zoomWidget->zoom);
p = wrapper->box.getTopRight();
p = wrapper->box.getTopRight().plus(math::Vec(20, 0));
} }
} }
} }


+ 5
- 2
src/app/ModuleWidget.cpp View File

@@ -22,8 +22,11 @@ ModuleWidget::ModuleWidget(Module *module) {
} }


ModuleWidget::~ModuleWidget() { 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 // Remove and delete the Module instance
if (module) { if (module) {
context()->engine->removeModule(module); context()->engine->removeModule(module);


+ 4
- 1
src/app/PortWidget.cpp View File

@@ -25,7 +25,10 @@ PortWidget::PortWidget() {
PortWidget::~PortWidget() { PortWidget::~PortWidget() {
// plugLight is not a child and is thus owned by the PortWidget, so we need to delete it here // plugLight is not a child and is thus owned by the PortWidget, so we need to delete it here
delete plugLight; 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() { void PortWidget::step() {


+ 7
- 0
src/app/RackWidget.cpp View File

@@ -458,6 +458,13 @@ void RackWidget::addModule(ModuleWidget *m) {
moduleContainer->addChild(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) { void RackWidget::deleteModule(ModuleWidget *m) {
moduleContainer->removeChild(m); moduleContainer->removeChild(m);
} }


+ 3
- 0
src/app/Scene.cpp View File

@@ -28,6 +28,9 @@ Scene::Scene() {
scrollWidget->box.pos.y = toolbar->box.size.y; scrollWidget->box.pos.y = toolbar->box.size.y;
} }


Scene::~Scene() {
}

void Scene::step() { void Scene::step() {
// Resize owned descendants // Resize owned descendants
toolbar->box.size.x = box.size.x; toolbar->box.size.x = box.size.x;


Loading…
Cancel
Save