Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Mainwindow closes when I close PCL window.
Forum Updated to NodeBB v4.3 + New Features

Mainwindow closes when I close PCL window.

Scheduled Pinned Locked Moved Unsolved General and Desktop
pcl
29 Posts 4 Posters 5.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    surajj4837
    wrote on 3 May 2021, 07:17 last edited by surajj4837 5 Mar 2021, 07:27
    #1

    I m using Qt 5.9.9 with PCL 1.10. in Ubuntu 20.04. I m trying to visualise a point cloud data with click of a button. I m able to do that but once I close the cloud viewer the main window also closes.
    Following error appears on output screen:

    12:43:07: Starting /home/suraj/PCL_Project/build-Qt_PCL_integration-Desktop_Qt_5_9_9_GCC_64bit-Debug/Qt_PCL_integration ...
    terminate called after throwing an instance of 'std::system_error'
      what():  Invalid argument
    12:43:13: The program has unexpectedly finished.
    12:43:13: The process was ended forcefully.
    12:43:13: /home/suraj/PCL_Project/build-Qt_PCL_integration-Desktop_Qt_5_9_9_GCC_64bit-Debug/Qt_PCL_integration crashed.
    

    I have uploaded code and pcd file here.
    Any suggestion on this?

    Qt_PCL_integration.png

    J 1 Reply Last reply 3 May 2021, 07:23
    0
    • S surajj4837
      3 May 2021, 07:17

      I m using Qt 5.9.9 with PCL 1.10. in Ubuntu 20.04. I m trying to visualise a point cloud data with click of a button. I m able to do that but once I close the cloud viewer the main window also closes.
      Following error appears on output screen:

      12:43:07: Starting /home/suraj/PCL_Project/build-Qt_PCL_integration-Desktop_Qt_5_9_9_GCC_64bit-Debug/Qt_PCL_integration ...
      terminate called after throwing an instance of 'std::system_error'
        what():  Invalid argument
      12:43:13: The program has unexpectedly finished.
      12:43:13: The process was ended forcefully.
      12:43:13: /home/suraj/PCL_Project/build-Qt_PCL_integration-Desktop_Qt_5_9_9_GCC_64bit-Debug/Qt_PCL_integration crashed.
      

      I have uploaded code and pcd file here.
      Any suggestion on this?

      Qt_PCL_integration.png

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 3 May 2021, 07:23 last edited by
      #2

      @surajj4837 said in Mainwindow closes when I close PCL window.:

      Any suggestion on this?

      No, not enough information.
      Please run your app through debugger (first thing to do in such situations) and post the stack trace after crash.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S Offline
        S Offline
        surajj4837
        wrote on 3 May 2021, 07:55 last edited by
        #3

        I did some debugging, after the destructor is called the problem starts:

        viewer.~CloudViewer();
        

        After execution of the statement following error window pops up.
        Error.png

        J 1 Reply Last reply 3 May 2021, 07:57
        0
        • S surajj4837
          3 May 2021, 07:55

          I did some debugging, after the destructor is called the problem starts:

          viewer.~CloudViewer();
          

          After execution of the statement following error window pops up.
          Error.png

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 3 May 2021, 07:57 last edited by jsulm 5 Mar 2021, 07:58
          #4

          @surajj4837 said in Mainwindow closes when I close PCL window.:

          viewer.~CloudViewer();

          ?
          This is not how destructors are usually called in C++.
          It has to be

          delete viewer;
          

          Is viewer actually allocated on the stack? Please show relevant code.
          Also, does viewer have a parent set?
          And you still did not post the stack trace.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply 3 May 2021, 08:03
          0
          • S Offline
            S Offline
            surajj4837
            wrote on 3 May 2021, 08:01 last edited by
            #5

            By stack trace do you mean this window:

            dd92e1c7-5755-41d5-9f7a-d5b3cf079b8e-image.png

            J J 2 Replies Last reply 3 May 2021, 08:02
            0
            • S surajj4837
              3 May 2021, 08:01

              By stack trace do you mean this window:

              dd92e1c7-5755-41d5-9f7a-d5b3cf079b8e-image.png

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 3 May 2021, 08:02 last edited by
              #6

              @surajj4837 Please show the code where you're using viewer and answer my other questions. viewer seems to be allocated on the stack, so no need to delete it (even less so calling the destrcutor directly)!

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply 3 May 2021, 08:03
              0
              • J jsulm
                3 May 2021, 07:57

                @surajj4837 said in Mainwindow closes when I close PCL window.:

                viewer.~CloudViewer();

                ?
                This is not how destructors are usually called in C++.
                It has to be

                delete viewer;
                

                Is viewer actually allocated on the stack? Please show relevant code.
                Also, does viewer have a parent set?
                And you still did not post the stack trace.

                S Offline
                S Offline
                surajj4837
                wrote on 3 May 2021, 08:03 last edited by
                #7

                @jsulm when I write viewer. it provides a list of inbuilt functions which also has the destructor in it. So I called it that way.

                1 Reply Last reply
                0
                • S surajj4837
                  3 May 2021, 08:01

                  By stack trace do you mean this window:

                  dd92e1c7-5755-41d5-9f7a-d5b3cf079b8e-image.png

                  J Offline
                  J Offline
                  JonB
                  wrote on 3 May 2021, 08:03 last edited by
                  #8

                  @surajj4837
                  Yes.

                  So what does line #55 of your MainWindow::on_pushButton_clicked do? Looks like there is a clue about destructing a CloudViewer?

                  S 1 Reply Last reply 3 May 2021, 08:10
                  0
                  • J jsulm
                    3 May 2021, 08:02

                    @surajj4837 Please show the code where you're using viewer and answer my other questions. viewer seems to be allocated on the stack, so no need to delete it (even less so calling the destrcutor directly)!

                    S Offline
                    S Offline
                    surajj4837
                    wrote on 3 May 2021, 08:03 last edited by
                    #9

                    @jsulm

                    void MainWindow::on_pushButton_clicked()
                    {
                        pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
                        pcl::io::loadPCDFile ("000000.pcd", *cloud);
                    
                        pcl::visualization::CloudViewer viewer("Cloud Viewer");
                    
                        //blocks until the cloud is actually rendered
                        viewer.showCloud(cloud);
                    
                        //use the following functions to get access to the underlying more advanced/powerful
                        //PCLVisualizer
                    
                        //This will only get called once
                        viewer.runOnVisualizationThreadOnce (viewerOneOff);
                    
                        //This will get called once per visualization iteration
                        viewer.runOnVisualizationThread (viewerPsycho);
                        while (!viewer.wasStopped ())
                        {
                            //you can also do cool processing here
                            //FIXME: Note that this is running in a separate thread from viewerPsycho
                            //and you should guard against race conditions yourself...
                            user_data++;
                        }
                    
                        std::cout << "Quit" << std::endl;
                    
                        viewer.~CloudViewer();
                        
                    }
                    
                    J J 2 Replies Last reply 3 May 2021, 08:04
                    0
                    • S surajj4837
                      3 May 2021, 08:03

                      @jsulm

                      void MainWindow::on_pushButton_clicked()
                      {
                          pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
                          pcl::io::loadPCDFile ("000000.pcd", *cloud);
                      
                          pcl::visualization::CloudViewer viewer("Cloud Viewer");
                      
                          //blocks until the cloud is actually rendered
                          viewer.showCloud(cloud);
                      
                          //use the following functions to get access to the underlying more advanced/powerful
                          //PCLVisualizer
                      
                          //This will only get called once
                          viewer.runOnVisualizationThreadOnce (viewerOneOff);
                      
                          //This will get called once per visualization iteration
                          viewer.runOnVisualizationThread (viewerPsycho);
                          while (!viewer.wasStopped ())
                          {
                              //you can also do cool processing here
                              //FIXME: Note that this is running in a separate thread from viewerPsycho
                              //and you should guard against race conditions yourself...
                              user_data++;
                          }
                      
                          std::cout << "Quit" << std::endl;
                      
                          viewer.~CloudViewer();
                          
                      }
                      
                      J Offline
                      J Offline
                      JonB
                      wrote on 3 May 2021, 08:04 last edited by
                      #10

                      @surajj4837 said in Mainwindow closes when I close PCL window.:

                      viewer.~CloudViewer();

                      Ummm??

                      1 Reply Last reply
                      0
                      • S surajj4837
                        3 May 2021, 08:03

                        @jsulm

                        void MainWindow::on_pushButton_clicked()
                        {
                            pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
                            pcl::io::loadPCDFile ("000000.pcd", *cloud);
                        
                            pcl::visualization::CloudViewer viewer("Cloud Viewer");
                        
                            //blocks until the cloud is actually rendered
                            viewer.showCloud(cloud);
                        
                            //use the following functions to get access to the underlying more advanced/powerful
                            //PCLVisualizer
                        
                            //This will only get called once
                            viewer.runOnVisualizationThreadOnce (viewerOneOff);
                        
                            //This will get called once per visualization iteration
                            viewer.runOnVisualizationThread (viewerPsycho);
                            while (!viewer.wasStopped ())
                            {
                                //you can also do cool processing here
                                //FIXME: Note that this is running in a separate thread from viewerPsycho
                                //and you should guard against race conditions yourself...
                                user_data++;
                            }
                        
                            std::cout << "Quit" << std::endl;
                        
                            viewer.~CloudViewer();
                            
                        }
                        
                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 3 May 2021, 08:05 last edited by
                        #11

                        @surajj4837 As I thought: viewer is allocated on the STACK not heap. So, no need to delete it!
                        Remove viewer.~CloudViewer();

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        S 1 Reply Last reply 3 May 2021, 08:08
                        1
                        • J jsulm
                          3 May 2021, 08:05

                          @surajj4837 As I thought: viewer is allocated on the STACK not heap. So, no need to delete it!
                          Remove viewer.~CloudViewer();

                          S Offline
                          S Offline
                          surajj4837
                          wrote on 3 May 2021, 08:08 last edited by
                          #12

                          @jsulm That was the original problem I started with. The following statement was not there earlier

                          viewer.~CloudViewer();
                          

                          But when I clicked on close button of viewer the cloudviewer window still existed on screen, so I tried closing through code. But that raised the error.

                          J 1 Reply Last reply 3 May 2021, 08:10
                          0
                          • J JonB
                            3 May 2021, 08:03

                            @surajj4837
                            Yes.

                            So what does line #55 of your MainWindow::on_pushButton_clicked do? Looks like there is a clue about destructing a CloudViewer?

                            S Offline
                            S Offline
                            surajj4837
                            wrote on 3 May 2021, 08:10 last edited by
                            #13

                            @JonB

                            This viewer declaration is in line #55:

                            pcl::visualization::CloudViewer viewer("Cloud Viewer");
                            

                            When destructor is called the execution jumps to that line.

                            J J 2 Replies Last reply 3 May 2021, 08:13
                            0
                            • S surajj4837
                              3 May 2021, 08:08

                              @jsulm That was the original problem I started with. The following statement was not there earlier

                              viewer.~CloudViewer();
                              

                              But when I clicked on close button of viewer the cloudviewer window still existed on screen, so I tried closing through code. But that raised the error.

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 3 May 2021, 08:10 last edited by
                              #14

                              @surajj4837 said in Mainwindow closes when I close PCL window.:

                              But when I clicked on close button of viewer the cloudviewer window still existed on screen

                              Then debug your code instead of doing strange things like deleting stack allocated objecs. Probably you're hanging in while (!viewer.wasStopped ()) loop.

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              1
                              • S surajj4837
                                3 May 2021, 08:10

                                @JonB

                                This viewer declaration is in line #55:

                                pcl::visualization::CloudViewer viewer("Cloud Viewer");
                                

                                When destructor is called the execution jumps to that line.

                                J Offline
                                J Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on 3 May 2021, 08:13 last edited by
                                #15

                                @surajj4837 Also, does pcl::visualization::CloudViewer allocate the actual dialog on the heap?

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                S 1 Reply Last reply 3 May 2021, 08:25
                                0
                                • S surajj4837
                                  3 May 2021, 08:10

                                  @JonB

                                  This viewer declaration is in line #55:

                                  pcl::visualization::CloudViewer viewer("Cloud Viewer");
                                  

                                  When destructor is called the execution jumps to that line.

                                  J Offline
                                  J Offline
                                  JonB
                                  wrote on 3 May 2021, 08:14 last edited by
                                  #16

                                  @surajj4837
                                  For one thing, because of your

                                  pcl::visualization::CloudViewer viewer("Cloud Viewer");
                                  

                                  local variable this will be automatically destructed on reaching the end of function's } scope. You shouldn't call the destructor explicitly, even if that was OK I imagine it would cause double-destruction on exiting the method....

                                  S 1 Reply Last reply 3 May 2021, 08:27
                                  1
                                  • J jsulm
                                    3 May 2021, 08:13

                                    @surajj4837 Also, does pcl::visualization::CloudViewer allocate the actual dialog on the heap?

                                    S Offline
                                    S Offline
                                    surajj4837
                                    wrote on 3 May 2021, 08:25 last edited by
                                    #17

                                    @jsulm The CloudViewer constructor definition says it creates the object on heap.

                                    J 1 Reply Last reply 3 May 2021, 08:30
                                    0
                                    • J JonB
                                      3 May 2021, 08:14

                                      @surajj4837
                                      For one thing, because of your

                                      pcl::visualization::CloudViewer viewer("Cloud Viewer");
                                      

                                      local variable this will be automatically destructed on reaching the end of function's } scope. You shouldn't call the destructor explicitly, even if that was OK I imagine it would cause double-destruction on exiting the method....

                                      S Offline
                                      S Offline
                                      surajj4837
                                      wrote on 3 May 2021, 08:27 last edited by
                                      #18

                                      @JonB https://www.geeksforgeeks.org/possible-call-constructor-destructor-explicitly/

                                      Christian EhrlicherC J 2 Replies Last reply 3 May 2021, 08:28
                                      0
                                      • S surajj4837
                                        3 May 2021, 08:27

                                        @JonB https://www.geeksforgeeks.org/possible-call-constructor-destructor-explicitly/

                                        Christian EhrlicherC Online
                                        Christian EhrlicherC Online
                                        Christian Ehrlicher
                                        Lifetime Qt Champion
                                        wrote on 3 May 2021, 08:28 last edited by Christian Ehrlicher 5 Mar 2021, 08:29
                                        #19

                                        @surajj4837 You must not call a dtor for an object when you created it on the stack as you did - no matter if you call it in an unusual way like you did or with the correct c++ way by calling delete. C++ basics.

                                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                        Visit the Qt Academy at https://academy.qt.io/catalog

                                        S 1 Reply Last reply 3 May 2021, 08:31
                                        1
                                        • S surajj4837
                                          3 May 2021, 08:27

                                          @JonB https://www.geeksforgeeks.org/possible-call-constructor-destructor-explicitly/

                                          J Offline
                                          J Offline
                                          JonB
                                          wrote on 3 May 2021, 08:28 last edited by JonB 5 Mar 2021, 08:29
                                          #20

                                          @surajj4837

                                          @JonB https://www.geeksforgeeks.org/possible-call-constructor-destructor-explicitly/

                                          Explicit call to destructor is only necessary when object is placed at particular location in memory by using placement new.

                                          Do you have any evidence this is the case for you?

                                          S 1 Reply Last reply 3 May 2021, 08:31
                                          0

                                          1/29

                                          3 May 2021, 07:17

                                          • Login

                                          • Login or register to search.
                                          1 out of 29
                                          • First post
                                            1/29
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved