Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the visualization: : PCLVisualizer spinOnce() in child thread calls it the core dump #6206

Open
GodLiu1 opened this issue Dec 23, 2024 · 0 comments
Labels
kind: bug Type of issue status: triage Labels incomplete

Comments

@GodLiu1
Copy link

GodLiu1 commented Dec 23, 2024

Describe the bug

Calling pcl::visualization::PCLVisualizer spinOnce() in a child thread terminates the program (core dump)

Current Behavior

ERROR: In /build/vtk7-kRjOS9/vtk7-7.1.1+dfsg2/Rendering/OpenGL2/vtkShaderProgram.cxx, line 379
vtkShaderProgram (0xffff601fb7f0): 1: #version 120
2: #ifdef GL_ES
3: #if VERSION == 300
4: #define attribute in
5: #define varying out
6: #endif // 300
7: #else // GL_ES
8: #define highp
9: #define mediump
10: #define lowp
11: #if VERSION == 150
12: #define attribute in
13: #define varying out
14: #endif
15: #endif // GL_ES
16:
17:
18: /=========================================================================
19:
20: Program: Visualization Toolkit
21: Module: vtkPolyDataVS.glsl
22:
23: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
24: All rights reserved.
25: See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
26:
27: This software is distributed WITHOUT ANY WARRANTY; without even
28: the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
29: PURPOSE. See the above copyright notice for more information.
30:
31: =========================================================================
/
32:
33: attribute vec4 vertexMC;
34:
35: // frag position in VC
36: varying vec4 vertexVCVSOutput;
37:
38: // optional normal declaration
39: //VTK::Normal::Dec
40:
41: // extra lighting parameters
42: //VTK::Light::Dec
43:
44: // Texture coordinates
45: //VTK::TCoord::Dec
46:
47: // material property values
48: //VTK::Color::Dec
49:
50: // clipping plane vars
51: //VTK::Clip::Dec
52:
53: // camera and actor matrix values
54: uniform mat4 MCDCMatrix;
55: uniform mat4 MCVCMatrix;
56:
57: // Apple Bug
58: //VTK::PrimID::Dec
59:
60: // Value raster
61: //VTK::ValuePass::Dec
62:
63: void main()
64: {
65: //VTK::Color::Impl
66:
67: //VTK::Normal::Impl
68:
69: //VTK::TCoord::Impl
70:
71: //VTK::Clip::Impl
72:
73: //VTK::PrimID::Impl
74:
75: vertexVCVSOutput = MCVCMatrix * vertexMC;
76: gl_Position = MCDCMatrix * vertexMC;
77:
78:
79: //VTK::ValuePass::Impl
80:
81: //VTK::Light::Impl
82: }
83:

ERROR: In /build/vtk7-kRjOS9/vtk7-7.1.1+dfsg2/Rendering/OpenGL2/vtkShaderProgram.cxx, line 380
vtkShaderProgram (0xffff601fb7f0):

Segmentation fault (core dumped)

To Reproduce
In the following code, the commented out code works fine, but if the code is executed in the child thread, an error will be reported and core dump will occur

`// #include <rclcpp/rclcpp.hpp>
// #include <sensor_msgs/msg/point_cloud2.hpp>
// #include <pcl/point_cloud.h>
// #include <pcl/point_types.h>
// #include <pcl/visualization/pcl_visualizer.h>
// #include <pcl_conversions/pcl_conversions.h>

// class PointCloudSubscriber : public rclcpp::Node {
// public:
// PointCloudSubscriber()
// : Node("point_cloud_subscriber"), viewer("PointCloud Viewer") {
// // 创建订阅器
// subscription_ = this->create_subscription<sensor_msgs::msg::PointCloud2>(
// "/front/tanway_points", 10,
// std::bind(&PointCloudSubscriber::pointCloudCallback, this, std::placeholders::_1));

// // 初始化 PCL 可视化器
// viewer.setBackgroundColor(0, 0, 0);
// viewer.addCoordinateSystem(1.0);
// viewer.initCameraParameters();
// }

// void spin() {
// while (rclcpp::ok()) {
// rclcpp::spin_some(this->get_node_base_interface());
// }
// }

// private:
// void pointCloudCallback(const sensor_msgs::msg::PointCloud2::SharedPtr msg) {
// pcl::PointCloudpcl::PointXYZ::Ptr cloud(new pcl::PointCloudpcl::PointXYZ());
// pcl::fromROSMsg(*msg, *cloud);

// // 更新点云到可视化器
// if (!viewer.updatePointCloudpcl::PointXYZ(cloud, "sample cloud")) {
// viewer.addPointCloudpcl::PointXYZ(cloud, "sample cloud");
// }
// viewer.spinOnce(100);
// }

// rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr subscription_;
// pcl::visualization::PCLVisualizer viewer;
// };

// int main(int argc, char** argv) {
// rclcpp::init(argc, argv);
// auto node = std::make_shared();
// node->spin();
// rclcpp::shutdown();
// return 0;
// }
#include <rclcpp/rclcpp.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl_conversions/pcl_conversions.h>
#include
#include
#include

pcl::visualization::PCLVisualizer viewer;
class PointCloudSubscriber : public rclcpp::Node {
public:
PointCloudSubscriber()
: Node("point_cloud_subscriber") {
// 创建订阅器
subscription_ = this->create_subscription<sensor_msgs::msg::PointCloud2>(
"/front/tanway_points", 10,
std::bind(&PointCloudSubscriber::pointCloudCallback, this, std::placeholders::_1));

    // 初始化 PCL 可视化器
    viewer.setBackgroundColor(0, 0, 0);
    viewer.addCoordinateSystem(1.0);
    viewer.initCameraParameters();
}

void spin() {
    while (rclcpp::ok()) {
        rclcpp::spin_some(this->get_node_base_interface());
    }
}

private:
void pointCloudCallback(const sensor_msgs::msg::PointCloud2::SharedPtr msg) {
pcl::PointCloudpcl::PointXYZ::Ptr cloud(new pcl::PointCloudpcl::PointXYZ());
pcl::fromROSMsg(*msg, *cloud);

    // 更新点云到可视化器
    if (!viewer.updatePointCloud<pcl::PointXYZ>(cloud, "sample cloud")) {
        viewer.addPointCloud<pcl::PointXYZ>(cloud, "sample cloud");
    }
    viewer.spinOnce(100);
}

rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr subscription_;

};

int main(int argc, char** argv) {
rclcpp::init(argc, argv);
// 创建 ROS 节点
viewer=pcl::visualization::PCLVisualizer("PointCloud Viewer");
auto node = std::make_shared();

// 创建线程运行 ROS 节点
std::thread ros_thread([node]() {
    node->spin();
});

// 分离线程
ros_thread.detach();

// 主线程打印时间戳
while (rclcpp::ok()) {
    auto now = std::chrono::system_clock::now();
    auto time_t_now = std::chrono::system_clock::to_time_t(now);
    std::cout << "Current Time: " << std::ctime(&time_t_now);
    std::this_thread::sleep_for(std::chrono::seconds(1));
}

rclcpp::shutdown();
return 0;

}
`

Your Environment (please complete the following information):

  • OS: [e.g. Ubuntu 20.04]
  • Compiler: [:eg GCC 9.4]
  • PCL Version [e.g. 1.13.1, HEAD]
  • VTK Version [e.g. 7.1]

Possible Solution

Maybe installing a later version of vtk and recompiling pcl will work? I wonder if anyone has tried

@GodLiu1 GodLiu1 added kind: bug Type of issue status: triage Labels incomplete labels Dec 23, 2024
@GodLiu1 GodLiu1 changed the title [pcl] Provide a general summary of the issue the visualization: : PCLVisualizer spinOnce() in child thread calls it the core dump Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Type of issue status: triage Labels incomplete
Projects
None yet
Development

No branches or pull requests

1 participant