Skip to content

Commit

Permalink
Fix connect infinite loop in heat method plugin (#7605)
Browse files Browse the repository at this point in the history
## Summary of Changes

The proper fixes would be to prevent the "reset colors" and the creation
of a selection item from emitting "item changed": in neither case the
item changed. Future work...

## Release Management

* Affected package(s): `Polyhedron`
* Issue(s) solved (if any): -
* Feature/Small Feature (if any): -
* License and copyright ownership: no change
  • Loading branch information
sloriot authored Aug 14, 2023
2 parents bdbba81 + 7ec586c commit 464930e
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions Polyhedron/demo/Polyhedron/Plugins/Display/Heat_method_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,18 +605,25 @@ private Q_SLOTS:
sm_item->setRenderingMode(GouraudPlusEdges);
sm_item->redraw();

scene->addItem(heat_item);
scene->setSelectedItem(scene->item_id(sm_item));
auto heat_item_id = scene->addItem(heat_item);
scene->setSelectedItem(heat_item_id);

// any change of sm_item destroys everything
connect(sm_item, &Scene_surface_mesh_item::itemChanged,
this, [this, sm_item, heat_item]()
{
sm_item->resetColors();
removePluginProperties(sm_item);
scene->erase(scene->item_id(heat_item));
onItemIndicesSelected(scene->selectionIndices());
});

// @todo do not emit itemChanged when the colors are reset
// @todo with qt6, single connection can be performed with `static_cast<Qt::ConnectionType>(Qt::SingleShotConnection)`
// see https://www.kdab.com/single-shot-connections/
auto connection = std::make_shared<QMetaObject::Connection>();
*connection = connect(sm_item, &Scene_surface_mesh_item::itemChanged,
this, [this, sm_item, heat_item, connection]()
{
QObject::disconnect(*connection);

sm_item->resetColors();
removePluginProperties(sm_item);
scene->erase(scene->item_id(heat_item));
onItemIndicesSelected(scene->selectionIndices());
});

connect(sm_item, &Scene_surface_mesh_item::aboutToBeDestroyed,
this, [this, heat_item]()
Expand Down Expand Up @@ -765,7 +772,8 @@ private Q_SLOTS:

Scene_polyhedron_selection_item* source_vertices = new Scene_polyhedron_selection_item(sm_item, mw);
source_vertices->setName(tr("%1 (source vertices)").arg(sm_item->name()));
scene->addItem(source_vertices);
auto source_vertices_id = scene->addItem(source_vertices);
scene->setSelectedItem(source_vertices_id);

link_mesh_and_selection(sm_item, source_vertices);

Expand Down

0 comments on commit 464930e

Please sign in to comment.