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 removeChild(Widget *widget);
void clearChildren(); void clearChildren();
/** Recursively finalizes event start/end pairs as needed */
void finalizeEvents();


/** Advances the module by one frame */ /** Advances the module by one frame */
virtual void step(); 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_DELETE:
case GLFW_KEY_BACKSPACE: case GLFW_KEY_BACKSPACE:
gRackWidget->deleteModule(this); gRackWidget->deleteModule(this);
this->finalizeEvents();
delete this; delete this;
break; break;
case GLFW_KEY_I: case GLFW_KEY_I:
@@ -217,6 +218,7 @@ struct DeleteMenuItem : MenuItem {
ModuleWidget *moduleWidget; ModuleWidget *moduleWidget;
void onAction() { void onAction() {
gRackWidget->deleteModule(moduleWidget); gRackWidget->deleteModule(moduleWidget);
moduleWidget->finalizeEvents();
delete moduleWidget; delete moduleWidget;
} }
}; };


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

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


Port::~Port() { Port::~Port() {
disconnect(); 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() { void Port::disconnect() {


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

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




@@ -62,6 +63,28 @@ void Widget::clearChildren() {
children.clear(); 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() { void Widget::step() {
for (Widget *child : children) { for (Widget *child : children) {
child->step(); child->step();


Loading…
Cancel
Save