Ticket #10947 (new)

Opened 6 years ago

Last modified 5 years ago

BugFix: Observer issue of AlgorithmProxy

Reported by: Anton Piccardo-Selg Owned by: Anton Piccardo-Selg
Priority: major Milestone: Backlog
Component: Framework Keywords: Algorithm Observer
Cc: Blocked By:
Blocking: Tester:

Description

There are circumstances when an observer is not added to correctly to an algorithm. The bug appears when adding an NObserver to an algorithm and then opening an algorithm dialog which has been set with the same algorithm. The input checks of the algorithm dialog remove the underlying algorithm.

Example code structure which triggers the bug: A class A contains an NObserver

in A.h

#include "Poco/NObserver.h"
class A 
{
 public:
  A(){};
  ~A(){};
  void showDialog();

 private:
 
 // Callback function
  void handleAlgorithmFinishedNotification(const Poco::AutoPtr<Mantid::API::Algorithm::FinishedNotification>& pNf);
 
 // Observer
 Poco::NObserver<A, Mantid::API::Algorithm::FinishedNotification>  m_finishedObserver;
}


The callback itself is just

void A::handleAlgorithmFinishedNotification(const Poco::AutoPtr<Mantid::API::Algorithm::FinishedNotification>& pNf);
{
  //...never gets here
}

Inside the showDialog an algorithm is created and the m_finishedObserver is added to the list of observers of the algorithm. The algorithm is then added to an algorithm dialog

void A::showDialog()
{
 // Create algorithm
 Mantid::API::IAlgorithm_sptr algorithm = Mantid::API::AlgorithmManager::Instance().create("SliceMD",1);

 // Add observer
 algorithm->addObserver(m_finishedObserver);

 // Create dialog
 MantidQt::MantidWidgets::BinMDDialog* dialog = new MantidQt::MantidWidgets::BinMDDialog(this);
 dialog->setAttribute(Qt::WA_DeleteOnClose, true);
 dialog->setAlgorithm(algorithm);
 dialog->show();
 dialog->raise();
 dialog->activateWindow();
}

When the user presses accept on the algorithm dialog, the callback of class A is not executed, yet the callback of the AlgorithmMonitor is executed. The main places to look for a bug are the AlgorithmProxy. We noted that between original algorithm object was dropped between the addObserver call in the sample code and the addObserver call from within the AlgorithmMonitor.

Change History

comment:1 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 11786

Note: See TracTickets for help on using tickets.