From d8dfc1b0aa3cd591784255b0f9f5b588fecd21e8 Mon Sep 17 00:00:00 2001
From: "simon.fanetti" <simon.fanetti@etu.hesge.ch>
Date: Mon, 31 Aug 2020 21:03:42 +0200
Subject: [PATCH] fixed setup app ending seg fault

---
 README.md                              |  2 +-
 app/SandboxSetup/beamerlocationgui.cpp | 14 +++++++++-----
 app/SandboxSetup/camerafocusgui.cpp    |  7 ++++++-
 app/SandboxSetup/initcameragui.cpp     |  4 ++--
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index 6dad81c..dba5625 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,6 @@
  - LD_LIBRARY_PATH must contain dir's path to libsandbox.so
  - Enter this command in the terminal where you are using your application
 ```
-REALTIVE_PATH_TO_SO=../ar_sandbox_lib/build && \
+REALTIVE_PATH_TO_SO=../../ar_sandbox_lib/build && \
 export LD_LIBRARY_PATH=$(pwd)/$REALTIVE_PATH_TO_SO
 ```
diff --git a/app/SandboxSetup/beamerlocationgui.cpp b/app/SandboxSetup/beamerlocationgui.cpp
index 213a2a1..51de4f5 100644
--- a/app/SandboxSetup/beamerlocationgui.cpp
+++ b/app/SandboxSetup/beamerlocationgui.cpp
@@ -30,6 +30,8 @@ BeamerLocationGui::BeamerLocationGui(SandboxSetup *_setup, MonitorGui *_mg, QWid
 BeamerLocationGui::~BeamerLocationGui()
 {
     delete timer;
+    myThread->quit();
+    myThread->wait();
     delete myThread;
     delete mut;
     delete winFullScreen;
@@ -37,13 +39,13 @@ BeamerLocationGui::~BeamerLocationGui()
 }
 
 void BeamerLocationGui::valideRoutine(){
-    endRoutine();
-    beamer->setPosition( (cv::Point3f)beamer->approximatePosition(&bases, &directions) );
+    //endRoutine();
+    //beamer->setPosition( (cv::Point3f)beamer->approximatePosition(&bases, &directions) );
     endSuccess = true;
 }
 
 void BeamerLocationGui::cancelRoutine(){
-    endRoutine();
+    //endRoutine();
     endSuccess = false;
 }
 
@@ -59,6 +61,8 @@ void BeamerLocationGui::showEvent(QShowEvent *event){
 
 void BeamerLocationGui::closeEvent(QCloseEvent *e){
     endRoutine();
+    if(endSuccess)
+        beamer->setPosition( (cv::Point3f)beamer->approximatePosition(&bases, &directions) );
     QWidget::closeEvent(e);
 }
 
@@ -77,7 +81,7 @@ void BeamerLocationGui::startRoutine(){
     updateLabelSteps();
 
     if(myThread->isRunning()){
-        myThread->exit(0);
+        myThread->quit();
         myThread->wait();
     }
 
@@ -167,7 +171,7 @@ void BeamerLocationGui::userValidePoint(){
 void BeamerLocationGui::endRoutine(){
 
     timer->stop();
-    myThread->exit(0);
+    myThread->quit();
     myThread->wait();
 
     endSuccess = (bases.size() == beamer->MAX_LINEAR_LINE_POINTS && directions.size() == beamer->MAX_LINEAR_LINE_POINTS);
diff --git a/app/SandboxSetup/camerafocusgui.cpp b/app/SandboxSetup/camerafocusgui.cpp
index 724ebda..fb3c5ae 100644
--- a/app/SandboxSetup/camerafocusgui.cpp
+++ b/app/SandboxSetup/camerafocusgui.cpp
@@ -31,7 +31,7 @@ CameraFocusGui::~CameraFocusGui()
 {
     delete frameTimer;
     delete blackScreen;
-    myThread->exit(0);
+    myThread->quit();
     myThread->wait();
     delete myThread;
     delete ui;
@@ -50,9 +50,14 @@ void CameraFocusGui::showEvent(QShowEvent *event){
     frameTimer->start(100);
 }
 
+
+// TODO : Fixe bug timer
+
 void CameraFocusGui::closeEvent(QCloseEvent *event){
 
     frameTimer->stop();
+    myThread->quit();
+    myThread->wait();
     blackScreen->close();
     QWidget::closeEvent(event);
 }
diff --git a/app/SandboxSetup/initcameragui.cpp b/app/SandboxSetup/initcameragui.cpp
index 7b06f0d..14a434d 100644
--- a/app/SandboxSetup/initcameragui.cpp
+++ b/app/SandboxSetup/initcameragui.cpp
@@ -26,11 +26,11 @@ InitCameraGui::InitCameraGui(SandboxSetup *_setup, QWidget *parent) :
 
     workerThread = new CameraStartThread(setup->getCamera());
     connect(workerThread, &CameraStartThread::setupReady, this, &InitCameraGui::setupReady);
-    connect(workerThread, &CameraStartThread::finished, workerThread, &QObject::deleteLater);
+    //connect(workerThread, &QThread::finished, workerThread, &QObject::deleteLater); // delete thread when finished
 }
 
 InitCameraGui::~InitCameraGui()
-{   
+{
     workerThread->quit();
     workerThread->wait();
     delete workerThread;
-- 
GitLab