C++ 程序在PCL可视化错误期间崩溃

C++ 程序在PCL可视化错误期间崩溃,c++,C++,我是PCL(点云库)的新手。我使用默认的多功能安装程序安装PCL。visual studio版本为2019。 现在,我想运行简单的PCD可视化代码,如下所示: ''' #包括 #包括 #包括 #包括 int用户_数据; 无效的 viewerOnOff(pcl::visualization::PCLVisualizer&viewer) { 查看器.setBackgroundColor(1.0,0.5,1.0); pcl::pointxyzo; o、 x=1.0; o、 y=0; o、 z=0; a

我是PCL(点云库)的新手。我使用默认的多功能安装程序安装PCL。visual studio版本为2019。 现在,我想运行简单的PCD可视化代码,如下所示: '''

#包括
#包括
#包括
#包括
int用户_数据;
无效的
viewerOnOff(pcl::visualization::PCLVisualizer&viewer)
{
查看器.setBackgroundColor(1.0,0.5,1.0);
pcl::pointxyzo;
o、 x=1.0;
o、 y=0;
o、 z=0;
addSphere(o,0.25,“sphere”,0);

很抱歉,我不知道我笔记本电脑上以前的NVIDIA驱动程序的版本号。 巧合的是,昨天我的电脑上运行的一个游戏因为“NVWGF2UMX.DLL”而崩溃了。官方的解决方案是重新安装英伟达驱动程序的最新版本。 结果,游戏成功了,帖子中的bug也消失了。
我希望这个答案将来会对其他人有所帮助。

在调试器下运行它,看看它在哪里崩溃,并检查导致崩溃的变量?我尝试了这种方法。当程序在这一行上运行时(pcl::visualization::CloudViewer(“CloudViewer”);),编译器告诉我查找一个名为cloud_viewer.cpp的文件。但我没有编写它,然后在中找到了它‪F:\PCL\PCL 1.11.0\share\doc\PCL-1.11\tutorials\sources\cloud\u viewer\。然而,这只是一个示例程序。我很困惑。我找到了一个解决方案,就是重新安装图形驱动程序。它工作正常。做得好!如果你能写一个解释你有什么图形硬件和操作系统,以及哪个版本的答案对于您卸载/重新安装的驱动程序,这可能对未来的读者或搜索人员有用。
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>

int user_data;

void
viewerOneOff(pcl::visualization::PCLVisualizer& viewer)
{
    viewer.setBackgroundColor(1.0, 0.5, 1.0);
    pcl::PointXYZ o;
    o.x = 1.0;
    o.y = 0;
    o.z = 0;
    viewer.addSphere(o, 0.25, "sphere", 0);
    std::cout << "i only run once" << std::endl;

}

void
viewerPsycho(pcl::visualization::PCLVisualizer& viewer)
{
    static unsigned count = 0;
    std::stringstream ss;
    ss << "Once per viewer loop: " << count++;
    viewer.removeShape("text", 0);
    viewer.addText(ss.str(), 200, 300, "text", 0);

    //FIXME: possible race condition here:
    user_data++;
}

int
main()
{
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::io::loadPCDFile("C:/Users/Shinelon/Desktop/test_pcd.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++;
    }
    return 0;
}