Browse Source

Fixed segfaults resulting from deleting a module while dragging cables

and knobs
tags/v0.3.2
Andrew Belt 7 years ago
parent
commit
b4de457311
4 changed files with 34 additions and 0 deletions
  1. +2
    -0
      include/widgets.hpp
  2. +2
    -0
      src/app/ModuleWidget.cpp
  3. +7
    -0
      src/app/Port.cpp
  4. +23
    -0
      src/widgets/Widget.cpp

+ 2
- 0
include/widgets.hpp View File

@@ -76,6 +76,8 @@ struct Widget {
*/
void removeChild(Widget *widget);
void clearChildren();
/** Recursively finalizes event start/end pairs as needed */
void finalizeEvents();

/** Advances the module by one frame */
virtual void step();


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

@@ -155,6 +155,7 @@ Widget *ModuleWidget::onHoverKey(Vec pos, int key) {
case GLFW_KEY_DELETE:
case GLFW_KEY_BACKSPACE:
gRackWidget->deleteModule(this);
this->finalizeEvents();
delete this;
break;
case GLFW_KEY_I:
@@ -217,6 +218,7 @@ struct DeleteMenuItem : MenuItem {
ModuleWidget *moduleWidget;
void onAction() {
gRackWidget->deleteModule(moduleWidget);
moduleWidget->finalizeEvents();
delete moduleWidget;
}
};


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

@@ -9,6 +9,13 @@ Port::Port() {

Port::~Port() {
disconnect();

if (gRackWidget->activeWire) {
if (gRackWidget->activeWire->hoveredInputPort == this)
gRackWidget->activeWire->hoveredInputPort = NULL;
if (gRackWidget->activeWire->hoveredOutputPort == this)
gRackWidget->activeWire->hoveredOutputPort = NULL;
}
}

void Port::disconnect() {


+ 23
- 0
src/widgets/Widget.cpp View File

@@ -1,4 +1,5 @@
#include "widgets.hpp"
#include "app.hpp"
#include <algorithm>


@@ -62,6 +63,28 @@ void Widget::clearChildren() {
children.clear();
}

void Widget::finalizeEvents() {
// Stop dragging and hovering this widget
if (gHoveredWidget == this) {
gHoveredWidget->onMouseLeave();
gHoveredWidget = NULL;
}
if (gDraggedWidget == this) {
gDraggedWidget->onDragEnd();
gDraggedWidget = NULL;
}
if (gDragHoveredWidget == this) {
gDragHoveredWidget = NULL;
}
if (gSelectedWidget == this) {
gSelectedWidget->onDeselect();
gSelectedWidget = NULL;
}
for (Widget *child : children) {
child->finalizeEvents();
}
}

void Widget::step() {
for (Widget *child : children) {
child->step();


Loading…
Cancel
Save