Page MenuHomePhabricator | MITK

WeakPointer: Exception on OnDeleteEvent when closing MITK workbench
Open, NormalPublic

Description

OS: Windows (none other OS tested yet)

Description:
When using the mitk::WeakPointer in the QmitkNodeSelectionButton (part of the org.mitk.gui.qt.common plugin). I get a an exception when I am closing the application as soon as I have called mitk::WeakPointer::Lock().

The exception is raised in WeakPointer::OnDeleteEvent()

if (m_DeleteEventCallback)
  m_DeleteEventCallback();

When it tries to call m_DeleteEventCallback.

If I switch the implementation to use a SmartPointer in QmitkNodeSelectionButton everything works fine. But I would like to just use a weak pointer. And maybe this problem also points to more fundamental flaw.

Event Timeline

floca created this task.May 11 2018, 4:23 PM

What is the function you set as DeleteEventCallback?

floca added a comment.May 14 2018, 2:23 PM

What is the function you set as DeleteEventCallback?

None. I haven't set one explicitly.

Okay, strange. std::function implements the bool() operator for the check. The only thing I could imagine is that the implementation your toolchain is using, doesn't provide the operator and evaluates to something else. What compiler are you using?

floca added a comment.EditedMay 14 2018, 3:41 PM

I use VS2017 (windows 10).

One can provoke the violation when

  1. selecting a node
  2. clearing the workspace
  3. closing the view (e.g. Data Storage Viewer Test)

or

  1. selecting a node
  2. closing the view (e.g. Data Storage Viewer Test)
  3. closing the application

The violation is sometimes not provoked if I do the following

  1. selecting a node
  2. closing the view
  3. clearing the workspace
  4. closing the application

(but I had one try, where it crashes at 3).

I think it is some kind of "racing condition" may due to the timing when Qt relay destructs the widgets that has a weak pointer as member.

kislinsk triaged this task as Normal priority.Thu, Nov 22, 11:46 AM

Threading issue? Making WeakPointer thread-safe?

floca added a comment.Thu, Nov 22, 1:35 PM

Threading issue? Making WeakPointer thread-safe?

That wouldn't contradict the racing condition assumption. Isn't the WeakPointer thread-safe already?

https://itk.org/Doxygen413/html/ThreadingPage.html

I interpret the section about application-level multithreading as "do it yourself in terms of event mechanisms and stuff". So this is still my first guess. We should at least update the WeakPointer documentation or think about if and how we could get it to work anyways.