A quote from that thread that might help:
I've looked into the pcl code and into some vtk references and it seems to me that the odd Linux behavior depends on a potentially incomplete implementation of the vtkRendererWindowInteractor's specialization for the X environment (I'm not 100% sure about this though, I don't have enough knowledge of the vtk internals).
What makes me think so is the following:
The vtkRendererWindowInteractor's TerminateApp documentation states that the function "should be overridden by platform dependent subclasses to provide a termination procedure if one is required." The Win32 and MacOS versions apparently are doing so but the X version has those "question marks" in the docs. That leaves me thinking that the implementation might have some issues..Still, I'm not a vtk nor an X programming expert, I honestly have no idea. If someone else wants to take a look at this it might be better...
Can we build a small example that we can run to replicate this bug? I'm not familiar with the issue - I always assumed .close () works well.
The code snippet in #85 should be fine; I'm pasting it here to avoid confusion:
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
int main (int argc, char ** argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>());
pcl::io::loadPCDFile("bunny.pcd", *cloud);
{
pcl::visualization::PCLVisualizer viewer;
viewer.addPointCloud(cloud);
viewer.spin(); // if you press Q the spin loop terminates but
viewer.close(); // the window does not close,
// it remains open and frozen behind the new window
}
{
pcl::visualization::PCLVisualizer viewer;
viewer.addPointCloud(cloud);
viewer.spin();
viewer.close();
}
// both windows close now because the program terminates
}
I have the same problem with the CloudViewer, I posted it on the mailing list few months ago:
http://www.pcl-users.org/Closing-CloudViewer-td4032686.html
I opened an issue on the VTK bug tracker:
http://www.vtk.org/Bug/view.php?id=14985
This bug appears to still be extant. Thanks in advance for any help with it.
Please append a message to the VTK bug report so that it gains visibility!
Hi,
still no solution to that?
Nope, still no solution that I'm aware of. I bumped the VTK thread, for what it's worth.
Issue has moved to: https://gitlab.kitware.com/vtk/vtk/issues/14985
This has been fixed in 1.8.0: https://gitlab.kitware.com/vtk/vtk/issues/14985
I have tested with the latest VTK and PCL trunk; it works.
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
int main(void)
{
{
pcl::visualization::PCLVisualizer viewer;
viewer.spin();
viewer.close();
}
{
pcl::visualization::PCLVisualizer viewer;
viewer.spin();
viewer.close();
}
return 0;
}
The merge request that fixed the problem in VTK is marked for the 8.0.1 milestone, so I suppose this is the first version that has the problem fixed.
This bug still seems to exist in some form in 1.9.1. When I run the above test the window does not close. When I use spinOnce instead of spin it closes but only in the test case, and because the whole program closes. When the program doesn't close the window also does not close. I'm using following code:
#include <pcl/visualization/pcl_visualizer.h>
int main(void)
{
pcl::visualization::PCLVisualizer viewer;
viewer.spinOnce();
viewer.close();
while(true){}
}
I guess this is a bug? Is there a way to close the window with another method or a workaround?
@Kaju-Bubanja In my case, the line while(true){} was the cause of problem. Immediate pausing after viewer.close() will cause the viewer window to freeze, I don't know why. The code snippet above works for me:
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
int main(void)
{
{
pcl::visualization::PCLVisualizer viewer;
viewer.spin();
viewer.close();
}
{
pcl::visualization::PCLVisualizer viewer;
viewer.spin();
viewer.close();
}
return 0;
}
I was using pcl1.11 and vtk8.2.
I need to ask for some user input after visualizing clouds but the viewer does not close when quitted.
Setup: PCL1.11 and VTK8.2 on Ubuntu 20.04.
Code to reproduce:
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
int main(void)
{
{
pcl::visualization::PCLVisualizer viewer;
viewer.spin();
viewer.close();
} // closes fine
{
pcl::visualization::PCLVisualizer viewer;
viewer.spin();
viewer.close();
} // will not close until return 0
cout << "Input: ";
cin >> type;
cout << type;
return 0;
}
When waiting for a user input the viewer window wont close until the application ends. Any ideas on how to get the viewer window closed before continuing with cin?
When running:
{
pcl::visualization::PCLVisualizer viewer("viewer1");
viewer.spin();
viewer.close();
}
for(int i = 0; i < 100000; i++) {
std::cout << i;
}
std::cout << std::endl;
{
pcl::visualization::PCLVisualizer viewer("viewer2");
viewer.spin();
viewer.close();
}
also "viewer1" will freeze until the for loop is over.
It seems like the window will only close when a new window is opened or the applications ends.
Most helpful comment
This bug still seems to exist in some form in 1.9.1. When I run the above test the window does not close. When I use spinOnce instead of spin it closes but only in the test case, and because the whole program closes. When the program doesn't close the window also does not close. I'm using following code:
I guess this is a bug? Is there a way to close the window with another method or a workaround?