summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-09-26 13:14:16 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-09-26 13:30:04 +0200
commit164f8d8d473e571086583d86bb4ff9982abe54b4 (patch)
tree9a4a168ede7d89e774eced2283ef601445ad171b
parent90eca9f45e6f6481e59748a2ebf5ca6f51488f38 (diff)
gui, options: prevent options reset on tracker stop
They should only be reset when closing the module dialog window. This is a hack but otherwise we'd have to change all the modules. Issue: #466 Closes #466
-rw-r--r--gui/main-window.cpp9
-rw-r--r--options/scoped.cpp44
-rw-r--r--options/scoped.hpp9
3 files changed, 56 insertions, 6 deletions
diff --git a/gui/main-window.cpp b/gui/main-window.cpp
index 1730a806..43b7158b 100644
--- a/gui/main-window.cpp
+++ b/gui/main-window.cpp
@@ -474,7 +474,7 @@ void MainWindow::stopTracker()
if (!work)
return;
- //ui.game_name->setText("Not connected");
+ opts::set_teardown_flag(true); // XXX hack -sh 20160926
pose_update_timer.stop();
ui.pose_display->rotateBy_real(0, 0, 0, 0, 0, 0);
@@ -488,8 +488,6 @@ void MainWindow::stopTracker()
if (pFilterDialog)
pFilterDialog->unregister_filter();
- save_modules();
-
work = nullptr;
libs = SelectedLibraries();
@@ -497,10 +495,11 @@ void MainWindow::stopTracker()
double p[6] = {0,0,0, 0,0,0};
display_pose(p, p);
}
- updateButtonState(false, false);
- set_title();
+ opts::set_teardown_flag(false); // XXX hack -sh 20160926
+ updateButtonState(false, false);
+ set_title();
ui.btnStartTracker->setFocus();
}
diff --git a/options/scoped.cpp b/options/scoped.cpp
index e1ddbae2..b0677ad9 100644
--- a/options/scoped.cpp
+++ b/options/scoped.cpp
@@ -1,10 +1,52 @@
#include "scoped.hpp"
+#include <QApplication>
+#include <QThread>
+
+// for std::abort()
+#include <cstdlib>
+
+#include <QDebug>
namespace options {
+std::atomic_bool opts::teardown_flag(false);
+
+void opts::set_teardown_flag(bool value)
+{
+ ensure_thread();
+
+ // we don't use exceptions in the whole project so no need for unwind protection
+ // also the calls aren't nested so no need for CAS either
+ teardown_flag = value;
+}
+
+void opts::ensure_thread()
+{
+ // only as a bug check
+
+ const QThread* ui_thread = qApp->thread();
+ const QThread* curthread = QThread::currentThread();
+
+ if (ui_thread == nullptr)
+ abort();
+
+ if (ui_thread != curthread)
+ abort();
+}
+
opts::~opts()
{
- b->reload();
+ if (!is_tracker_teardown())
+ b->reload();
+#if 0
+ else
+ qDebug() << "in teardown, not reloading" << b->name();
+#endif
+}
+
+bool opts::is_tracker_teardown()
+{
+ return teardown_flag;
}
opts::opts(const QString &name) : b(make_bundle(name))
diff --git a/options/scoped.hpp b/options/scoped.hpp
index 52ae383d..4ad51fea 100644
--- a/options/scoped.hpp
+++ b/options/scoped.hpp
@@ -5,6 +5,8 @@
#include "export.hpp"
+#include <atomic>
+
namespace options {
struct OPENTRACK_OPTIONS_EXPORT opts
@@ -14,6 +16,13 @@ struct OPENTRACK_OPTIONS_EXPORT opts
opts& operator=(const opts&) = delete;
opts(const opts&) = delete;
~opts();
+
+ // XXX hack: the flag shouldn't be here as action at distance -sh 20160926
+ static void set_teardown_flag(bool value);
+private:
+ static std::atomic_bool teardown_flag;
+ static bool is_tracker_teardown();
+ static void ensure_thread();
};
}