Mainwindow closes when I close PCL window.
-
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
-
@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.
-
@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).
-
@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; }