Mainwindow closes when I close PCL window.
-
I did some debugging, after the destructor is called the problem starts:
viewer.~CloudViewer();
After execution of the statement following error window pops up.
-
@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 bedelete 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. -
By stack trace do you mean this window:
-
@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)!
-
@surajj4837
Yes.So what does line #55 of your
MainWindow::on_pushButton_clicked
do? Looks like there is a clue about destructing aCloudViewer
? -
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(); }
-
-
@surajj4837 As I thought: viewer is allocated on the STACK not heap. So, no need to delete it!
Remove viewer.~CloudViewer(); -
@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.
-
@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.
-
@surajj4837 Also, does pcl::visualization::CloudViewer allocate the actual dialog on the heap?
-
@surajj4837
For one thing, because of yourpcl::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.... -
-
Christian Ehrlicher Lifetime Qt Championreplied to surajj4837 on last edited by Christian Ehrlicher
@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.
-
@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?
-
@surajj4837 said in Mainwindow closes when I close PCL window.:
The CloudViewer constructor definition says it creates the object on heap
Please show its code. viewer itself is allocated on the stack as you can clearly see from your code...
-
@Christian-Ehrlicher Okay