Page MenuHomePhabricator

DataInteractor looses DataNode, gets non-working when removed/added to data storage
Closed, InvalidPublic

Description

I just ran into some very unexpected problem around interaction and wanted to ask if the following is known behavior or even work in progress for somebody:

  • a DataNode is already in DataStorage with an interactor assigned
  • you want to assign another parent to the DataNode, so to call Remove(node), then Add(node, new_parent)
  • the interactor is in a unhealthy/dead state now, having lost its DataNode pointer (DataInteractor::DeletedNode got called)

For experimentation, I attached a patch against current master. Apply the patch, activate the Point Set Interaction view, then add a new PointSet, move the mouse over render windows, and have a look at the console. You should see lots of messages like "WARNING: EventStateMachine: Empty DataNode received along with this Event 000000000A780070"

I guess this is another variation of http://bugs.mitk.org/show_bug.cgi?id=19329 where DataInteractor::DeletedNode was introduced.

While not a solution, a workaround is to perform the desired operation as follows:

auto interactor = node->GetDataInteractor();
node->SetDataInteractor(nullptr);
data_storage->Remove(node); // ! this will kill the attached interactor
data_storage->Add(node, .. something else or nothing ..);
interactor->SetDataNode(node);

For completeness:

  • I would expect the interactor not to receive events while its node is removed from DataStorage
  • I would expect the interactor to work as before when re-adding its node to (the same) DataStorage

Event Timeline

In fact, the fix of T19329 did brake more than it actually fixed. It's also the cause for T19627. The problem is the newly introduced DeletedNode method (horrible name for what it is actually doing!) in DataInteractor or to be more precise the call to this method in Dispatcher::RemoveDataInteractor() and therefore also in Dispatcher::AddDataInteractor(). You cannot safely add a data node to the data storage anymore, that already has attached an interactor. For example, if you listen in your plugin for the NodeAdded event and attach your interactor there, this will fail when the Dispatcher's turn for this event is still pending. That's the case for the measurement plugin, when it is alrady opened at program start. In debug mode this leads to crashes! The dispatcher deletes the interactor that was just added.

Removing the call to DataInteractor::DeletedNode from Dispatcher::RemoveDataInteractor will fix the crashes but leads to dangling references to the interactors which is the original problem described in T19329.

Daniel, is this still an issue after the fixes of T19627?

(In reply to Stefan Kislinskiy from comment #2)

Daniel, is this still an issue after the fixes of T19627?

Hi. I just retried what I had described. The problem seems not to occur anymore. Seems reasonable that this has been fixed by your changes. Thank you!

I'll close this bug.

kislinsk changed the task status from Invalid to Spite.Jun 27 2018, 1:30 PM
kislinsk added a project: Bulk Edit.
kislinsk changed the task status from Spite to Invalid.Jun 27 2018, 1:36 PM
kislinsk removed a project: Bulk Edit.