Skip to content

Commit

Permalink
Merge pull request #37074 from robertapplin/37071-fix-crash-due-to-tw…
Browse files Browse the repository at this point in the history
…ice-observer-subscribing

Fix crash due to subscribing observer twice to notification center
  • Loading branch information
peterfpeterson committed Mar 25, 2024
2 parents 52cbb99 + 033be36 commit 171b44b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/source/release/v6.9.1/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The changes are:
- Removed slit lookup that was specific to OFFSPEC in :ref:`algm-ReflectometryReductionOneLiveData` as it is no longer required and was causing regular crashes when running live data on OFFSPEC.
- Fixed a bug in :ref:`Elwin Tab <elwin>` of :ref:`Data Manipulation Interface <interface-inelastic-data-manipulation>` where changing integration range with the sliders did not change default integration range.
- Add sample log values to the live data workspace before the instrument is loaded in :ref:`algm-ReflectometryReductionOneLiveData` to ensure log values are available when setting the detector positions.
- Fixed a crash when using multiple Indirect or Inelastic interfaces. This crash was present on the :ref:`Bayes Fitting <interface-inelastic-bayes-fitting>` interface, but could also be replicated elsewhere.

Citation
--------
Expand All @@ -36,6 +37,7 @@ Changes in this version
* `37053 <https://github.com/mantidproject/mantid/pull/37053>`_ Load instrument after loading sample logs in ReflectometryReductionOneLiveData
* `37016 <https://github.com/mantidproject/mantid/pull/37016>`_ Fix sliders not changing integration limits in Elwin tab
* `36935 <https://github.com/mantidproject/mantid/pull/36935>`_ Fix regular live data crashes on OFFSPEC
* `37074 <https://github.com/mantidproject/mantid/pull/37074>`_ Fix crash on Indirect/Inelastic interfaces.

.. _download page: http://download.mantidproject.org

Expand Down
20 changes: 12 additions & 8 deletions qt/widgets/plotting/src/PreviewPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ constexpr auto LOG_SCALE = "Log";
constexpr auto SQUARE_SCALE = "Square";
constexpr auto SHOWALLERRORS = "Show all errors";
constexpr auto HIDEALLERRORS = "Hide all errors";

template <typename Observer> void modifyObserver(Observer &observer, bool const turnOn) {
auto &notificationCenter = AnalysisDataService::Instance().notificationCenter;
if (turnOn && !notificationCenter.hasObserver(observer)) {
notificationCenter.addObserver(observer);
} else if (!turnOn && notificationCenter.hasObserver(observer)) {
notificationCenter.removeObserver(observer);
}
}

} // namespace

namespace MantidQt::MantidWidgets {
Expand Down Expand Up @@ -77,14 +87,8 @@ PreviewPlot::~PreviewPlot() { watchADS(false); }
* @param on If true ADS observers are enabled else they are disabled
*/
void PreviewPlot::watchADS(bool on) {
auto &notificationCenter = AnalysisDataService::Instance().notificationCenter;
if (on) {
notificationCenter.addObserver(m_wsRemovedObserver);
notificationCenter.addObserver(m_wsReplacedObserver);
} else {
notificationCenter.removeObserver(m_wsReplacedObserver);
notificationCenter.removeObserver(m_wsRemovedObserver);
}
modifyObserver(m_wsReplacedObserver, on);
modifyObserver(m_wsRemovedObserver, on);
}

/**
Expand Down

0 comments on commit 171b44b

Please sign in to comment.