Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash due to subscribing observer twice to notification center #37074

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading