Mainwindow closes when I close PCL window.
-
@surajj4837
Yes.So what does line #55 of your
MainWindow::on_pushButton_clicked
do? Looks like there is a clue about destructing aCloudViewer
?wrote on 3 May 2021, 08:10 last edited byThis viewer declaration is in line #55:
pcl::visualization::CloudViewer viewer("Cloud Viewer");
When destructor is called the execution jumps to that line.
-
@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.
-
This viewer declaration is in line #55:
pcl::visualization::CloudViewer viewer("Cloud Viewer");
When destructor is called the execution jumps to that line.
@surajj4837 Also, does pcl::visualization::CloudViewer allocate the actual dialog on the heap?
-
This viewer declaration is in line #55:
pcl::visualization::CloudViewer viewer("Cloud Viewer");
When destructor is called the execution jumps to that line.
wrote on 3 May 2021, 08:14 last edited by@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.... -
@surajj4837 Also, does pcl::visualization::CloudViewer allocate the actual dialog on the heap?
wrote on 3 May 2021, 08:25 last edited by@jsulm The CloudViewer constructor definition says it creates the object on 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.... -
Lifetime Qt Championwrote on 3 May 2021, 08:28 last edited by Christian Ehrlicher 5 Mar 2021, 08:29
@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.
-
wrote on 3 May 2021, 08:28 last edited by JonB 5 Mar 2021, 08:29
@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?
-
@jsulm The CloudViewer constructor definition says it creates the object on heap.
@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...
-
@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.
wrote on 3 May 2021, 08:31 last edited by@Christian-Ehrlicher Okay
-
@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?
wrote on 3 May 2021, 08:31 last edited by@JonB No.
-
@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...
wrote on 3 May 2021, 08:32 last edited by@jsulm Official source code. Line #266.
-
@jsulm Official source code. Line #266.
-
@jsulm Official source code. Line #266.
@surajj4837 said in Mainwindow closes when I close PCL window.:
@jsulm Official source code. Line #266.
There the object itself creates a new object on the heap. Don't know what this should have to do with your object which you create on the stack though.
-
@jsulm Official source code. Line #266.
Lifetime Qt Championwrote on 3 May 2021, 08:35 last edited by jsulm 5 Mar 2021, 08:35@surajj4837 This does not change anything! viewer is allocated on the stack. Its constructor allocates something on the heap but that is deleted in the destructor. But you do not have to call destructor for objects allocated on the stack as it is called when the object is destroyed (if it leaves its scope). I suggest you learn C++ basics (memory management).
-
@jsulm Official source code. Line #266.
@surajj4837 Actually there seems to be a bug:
00270 pcl::visualization::CloudViewer::~CloudViewer () 00271 { 00272 impl_->quit_ = true; 00273 impl_->viewer_thread_.join(); 00274 } 00275
Destructor does not delete impl!
It should bepcl::visualization::CloudViewer::~CloudViewer () { impl_->quit_ = true; impl_->viewer_thread_.join(); delete impl; }
-
@surajj4837 This does not change anything! viewer is allocated on the stack. Its constructor allocates something on the heap but that is deleted in the destructor. But you do not have to call destructor for objects allocated on the stack as it is called when the object is destroyed (if it leaves its scope). I suggest you learn C++ basics (memory management).
wrote on 3 May 2021, 08:38 last edited by@jsulm Sure, I will do that.
22/29