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

[Visualization] CloudViewer segfaults with PCL 1.12.1 and VTK 9.1 on Ubuntu 22.04 #5237

Closed
senicko opened this issue Apr 24, 2022 · 15 comments
Closed

Comments

@senicko
Copy link

senicko commented Apr 24, 2022

Basic CloudViewer example compiles without any problem, but after running produced executable window appears and immediately dissapears and segmentation fault error is printed to the console.

Exact console output

sebastian@sebastian-ThinkPad-E14-Gen-2:~/projects/d435i/build$ ./main
Segmentation fault (core dumped)

Sometimes a warning is shown about deprecation of some things in VTK 9.0. As an example one of them says:

2022-04-24 17:19:16.544 (   0.233s) [        5F7AB640]vtkOpenGLPolyDataMapper:306   WARN| vtkOpenGLPolyDataMapper::GetVertexShaderCode was deprecated for VTK 9.0 and will be removed in a future version.  Use vtkOpenGLShaderProperty::GetVertexShaderCode instead.

This is output produced by gdb

Reading symbols from ./main...
(gdb) run
Starting program: /home/sebastian/projects/d435i/build/main 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff2771640 (LWP 40996)]
[New Thread 0x7fffe4242640 (LWP 41008)]
[New Thread 0x7fffe3a41640 (LWP 41009)]
[New Thread 0x7fffe3240640 (LWP 41010)]
[New Thread 0x7fffe2a3f640 (LWP 41011)]
[New Thread 0x7fffe223e640 (LWP 41012)]
[New Thread 0x7fffe1a3d640 (LWP 41013)]
[New Thread 0x7fffe123c640 (LWP 41014)]
[New Thread 0x7fffc3fff640 (LWP 41015)]
[New Thread 0x7fffc34fb640 (LWP 41016)]
[New Thread 0x7fffc30fa640 (LWP 41017)]
2022-04-24 17:40:18.453 (   0.384s) [        F2771640]vtkOpenGLPolyDataMapper:306   WARN| vtkOpenGLPolyDataMapper::GetVertexShaderCode was deprecated for VTK 9.0 and will be removed in a future version.  Use vtkOpenGLShaderProperty::GetVertexShaderCode instead.
2022-04-24 17:40:18.457 (   0.387s) [        F2771640]vtkOpenGLPolyDataMapper:298   WARN| vtkOpenGLPolyDataMapper::SetVertexShaderCode was deprecated for VTK 9.0 and will be removed in a future version.  Use vtkOpenGLShaderProperty::SetVertexShaderCode instead.
2022-04-24 17:40:18.457 (   0.387s) [        F2771640]vtkOpenGLPolyDataMapper:336   WARN| vtkOpenGLPolyDataMapper::GetGeometryShaderCode was deprecated for VTK 9.0 and will be removed in a future version.  Use vtkOpenGLShaderProperty::GetGeometryShaderCode instead.
2022-04-24 17:40:18.457 (   0.387s) [        F2771640]vtkOpenGLPolyDataMapper:328   WARN| vtkOpenGLPolyDataMapper::SetGeometryShaderCode was deprecated for VTK 9.0 and will be removed in a future version.  Use vtkOpenGLShaderProperty::SetGeometryShaderCode instead.
2022-04-24 17:40:18.457 (   0.387s) [        F2771640]vtkOpenGLPolyDataMapper:321   WARN| vtkOpenGLPolyDataMapper::GetFragmentShaderCode was deprecated for VTK 9.0 and will be removed in a future version.  Use vtkOpenGLShaderProperty::GetFragmentShaderCode instead.
2022-04-24 17:40:18.457 (   0.387s) [        F2771640]vtkOpenGLPolyDataMapper:313   WARN| vtkOpenGLPolyDataMapper::SetFragmentShaderCode was deprecated for VTK 9.0 and will be removed in a future version.  Use vtkOpenGLShaderProperty::SetFragmentShaderCode instead.
2022-04-24 17:40:18.459 (   0.389s) [        F2771640]vtkOpenGLPolyDataMapper:306   WARN| vtkOpenGLPolyDataMapper::GetVertexShaderCode was deprecated for VTK 9.0 and will be removed in a future version.  Use vtkOpenGLShaderProperty::GetVertexShaderCode instead.
2022-04-24 17:40:18.459 (   0.389s) [        F2771640]vtkOpenGLPolyDataMapper:298   WARN| vtkOpenGLPolyDataMapper::SetVertexShaderCode was deprecated for VTK 9.0 and will be removed in a future version.  Use vtkOpenGLShaderProperty::SetVertexShaderCode instead.
2022-04-24 17:40:18.459 (   0.389s) [        F2771640]vtkOpenGLPolyDataMapper:336   WARN| vtkOpenGLPolyDataMapper::GetGeometryShaderCode was deprecated for VTK 9.0 and will be removed in a future version.  Use vtkOpenGLShaderProperty::GetGeometryShaderCode instead.
2022-04-24 17:40:18.459 (   0.389s) [        F2771640]vtkOpenGLPolyDataMapper:328   WARN| vtkOpenGLPolyDataMapper::SetGeometryShaderCode was deprecated for VTK 9.0 and will be removed in a future version.  Use vtkOpenGLShaderProperty::SetGeometryShaderCode instead.
2022-04-24 17:40:18.462 (   0.393s) [        F2771640]vtkOpenGLPolyDataMapper:321   WARN| vtkOpenGLPolyDataMapper::GetFragmentShaderCode was deprecated for VTK 9.0 and will be removed in a future version.  Use vtkOpenGLShaderProperty::GetFragmentShaderCode instead.
2022-04-24 17:40:18.462 (   0.393s) [        F2771640]vtkOpenGLPolyDataMapper:313   WARN| vtkOpenGLPolyDataMapper::SetFragmentShaderCode was deprecated for VTK 9.0 and will be removed in a future version.  Use vtkOpenGLShaderProperty::SetFragmentShaderCode instead.
[New Thread 0x7fffc2cf9640 (LWP 41018)]
[Thread 0x7fffc3fff640 (LWP 41015) exited]
[Thread 0x7fffe223e640 (LWP 41012) exited]
[Thread 0x7fffe2a3f640 (LWP 41011) exited]
[Thread 0x7fffe3240640 (LWP 41010) exited]
[Thread 0x7fffe123c640 (LWP 41014) exited]
[Thread 0x7fffe1a3d640 (LWP 41013) exited]
[Thread 0x7fffe3a41640 (LWP 41009) exited]
[Thread 0x7fffe4242640 (LWP 41008) exited]

Thread 2 "main" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff2771640 (LWP 40996)]
0x00007ffff3b70b10 in _XEventsQueued () from /lib/x86_64-linux-gnu/libX11.so.6
(gdb) bt
#0  0x00007ffff3b70b10 in _XEventsQueued () from /lib/x86_64-linux-gnu/libX11.so.6
#1  0x00007ffff3b5d1a1 in XPending () from /lib/x86_64-linux-gnu/libX11.so.6
#2  0x00007ffff3c79b8f in vtkXRenderWindowInteractor::StartEventLoop() () from /lib/x86_64-linux-gnu/libvtkRenderingUI-9.1.so.1
#3  0x00007ffff7f1bf8c in pcl::visualization::PCLVisualizer::spinOnce(int, bool) () from /lib/x86_64-linux-gnu/libpcl_visualization.so.1.12
#4  0x00007ffff7f422f0 in pcl::visualization::CloudViewer::CloudViewer_impl::operator()() () from /lib/x86_64-linux-gnu/libpcl_visualization.so.1.12
#5  0x00007ffff73e12c3 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff7151b43 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#7  0x00007ffff71e3a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
(gdb)

Context
I want to create a simple app that will show some points in 3D space. I've installed PCL with apt install libpcl-dev. Then I've created a new project with the help of Using PCL in your own project tutorial. Finally I wrote a simple app that should just show the window.

Expected behavior
Window should open.

Current Behavior
Window appears and immediately dissapears and segmentation fault error is printed to console.

To Reproduce

  1. Install cpl using sudo apt install libpcl-dev
  2. Create a simple cmake project (docs)
  3. create build folder and run cmake mkdir build && cd build && cmake ..
  4. build and run make && ./main

Screenshots/Code snippets
This is my CMakeList.txt

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)

project(pcl_test)

find_package(PCL 1.3 REQUIRED COMPONENTS common io visualization)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

SET(CMAKE_CXX_FLAGS "-g")

add_executable(main main.cpp)
target_link_libraries(main ${PCL_LIBRARIES})

and this is my main.cpp

#include <pcl/visualization/cloud_viewer.h>

int main () {
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud;
  pcl::visualization::CloudViewer viewer("Simple Cloud Viewer");
  viewer.showCloud(cloud);

  while (!viewer.wasStopped()) {}
}
  • OS: Ubuntu 22.04
  • Compiler: GCC 11.2.0
  • PCL Version 1.12.1
  • VTK Version 9.1

I saw #5195, but I didn't find any solutions there.

I've tried to downgrade PCL to version 1.11.1 but for some reason after building from source it turned out that visualization module wasn't compiled and I couldn't figure out why. I've also tried to downgrade vtk to 7.1 too but I couldn't manage to compile it from source due to errors that were thrown for unknown reason.

@senicko senicko added kind: bug Type of issue status: triage Labels incomplete labels Apr 24, 2022
@larshg larshg removed the status: triage Labels incomplete label Apr 24, 2022
@larshg
Copy link
Contributor

larshg commented Apr 24, 2022

I can verify that it crashes. Also other examples when the interator object is used / destroyed. But it seems to be an issue in VTK - or miuse from PCL, with some new changes that we haven't taken into consideration.

@mvieth
Copy link
Member

mvieth commented May 1, 2022

I investigated and here is what I found:
PCL issues with the same problem: #5189 #5195 #5239
The function spin() calls the function Start() of vtkRenderWindowInteractor (on most Unix/Linux systems, the implementation vtkXRenderWindowInteractor is used, on Windows for example another implementation). The function spinOnce() also calls Start(), but sets a timer before. When the timer is done, it calls TerminateApp() of the interactor.
At the VTK project, I found this issue, which seems to describe the same problem: https://gitlab.kitware.com/vtk/vtk/-/issues/18372 . The affected versions seem to be 9.0.2, 9.0.3, 9.1.0 (Ubuntu 22.04 uses 9.1.0, Ubuntu 21.10 uses 9.0.1, which seems to be unaffected). On the VTK master branch, it seems to be fixed now, although I haven't confirmed that yet.
Having such a problem in a Ubuntu LTS version is pretty bad.

Possible solutions:

  1. Ask the VTK maintainers to release a version 9.1.1 where the problem is fixed. But I don't know whether this would be included in the Ubuntu 22.04 packages repositories (Side note: currently the next planned VTK release seems to be 9.2.0)
  2. Find a solution on the PCL side, e.g. by including a fixed version of vtkXRenderWindowInteractor which is used instead of VTK's broken vtkXRenderWindowInteractor for the problematic VTK versions. That way, future PCL versions can work with any VTK version. But for Ubuntu 22.04, even if we release a PCL 1.12.2, I don't know whether it would be included in the Ubuntu package repositories

A possible workaround on the PCL user side could be to replace spinOnce() with spin() where possible. That way, it still crashes after the viewer is closed, but at least displays the viewer correctly.

@pionex
Copy link

pionex commented May 4, 2022

I have verified the same problem. I am running Ubuntu 22.04 with the distro versions of the libs. The order of events on my system is:

Calling PCLVisualizer::SpinOnce() sets a timer that results in PCLVisualizer::ExitMainLoopTimerCallback getting called.
PCLVisualizer::ExitMainLoopTimerCallback calls the vtkXRenderWindowInteractor::TerminateApp which calls Finalize that ultimately closes the libX11 Display struct.

At some point later
vtkXRenderWindowInteractor::ProcessEvents is called resulting in a call to XPending on the now freed Display object
XPending tries specifically to access the xcb member of that Display struct and segfaults while accessing a null pointer

I am still trying to wrap my head around this logic in PclVisualizer::SpinOnce:

 DO_EVERY (1.0 / interactor_->GetDesiredUpdateRate (),
    exit_main_loop_timer_callback_->right_timer_id = interactor_->CreateRepeatingTimer (time);
    interactor_->Start ();
    interactor_->DestroyTimer (exit_main_loop_timer_callback_->right_timer_id);
  );

My best understanding is that the only way to stop the interactor (necessary for spinonce) is to use that timer to call TerminateApp. Since terminate always destroys the Display object (even in older versions of VTK), I am unclear how the display object is meant to be preserved.

@pionex
Copy link

pionex commented May 5, 2022

I have tried using VTK with the XRenderWindowInteractor patches that are currently on master. This fixes the segmentation fault, but there is still the same fundamental problem using the visualizer with spin once.

Calling TerminateApp to stop the interactor now sets a Done flag that causes the XWindow to get closed. PCL may need a custom Interactor that has a bool flag on that TerminateApp function that selectively sets the Done flag so that it can terminate the interactor event loop without closing the window. As it is now, as soon as SpinOnce is called, the window just closes.

@mvieth
Copy link
Member

mvieth commented May 5, 2022

@pionex I am currently looking into whether ProcessEvents can be used in spinOnce. It sounds like that would be the right way. But I think ProcessEvents is only available in newer VTK versions (>= VTK 9?)

@pionex
Copy link

pionex commented May 5, 2022

@mvieth - Good catch - I just tried a quick and dirty version and it works well. The interactor->Start() method calls the Initialize() method if it hasn't been called. I haven't yet found a way to access that internal state, so I just used a static variable in the PCLVisualizer::spinOnce method to call this once and otherwise just call processEvents(). I don't have any code for the spin rate at the moment, but seems like this is promising.

@mvieth
Copy link
Member

mvieth commented May 10, 2022

@pionex I created a draft pull request (#5252) -- I would appreciate it if you could take a look or even test it

@mvieth
Copy link
Member

mvieth commented May 27, 2022

Pull request #5252 is merged, so this problem is fixed on the master branch.
I also opened an issue for the Ubuntu package maintainers, asking them if they would release a patch for the bug in VTK for jammy (22.04) and kinetic (22.10). Let's see what they say.

@chibai
Copy link

chibai commented Oct 9, 2022

I'm sorry, I don't get itIs this problem solved???
I apt install every thing~~~
pcl 1.12.1 and vtk 9.1
I got the same problem

How can I solved it??

@yasamoka
Copy link
Contributor

yasamoka commented Oct 9, 2022

I'm sorry, I don't get itIs this problem solved??? I apt install every thing~~~ pcl 1.12.1 and vtk 9.1 I got the same problem How can I solved it??

You have to build from master.

@chibai
Copy link

chibai commented Oct 10, 2022

I'm sorry, I don't get itIs this problem solved??? I apt install every thing~~~ pcl 1.12.1 and vtk 9.1 I got the same problem How can I solved it??

You have to build from master.

OK, It worked!! Nice!!

@zoe9216
Copy link

zoe9216 commented May 6, 2023

I tried building from master on Ubuntu 22.04 with Qt 5.15.3 and I got this error when I ran cmake:

CMake Error at /usr/lib/x86_64-linux-gnu/cmake/Qt6Core/Qt6CoreVersionlessTargets.cmake:37 (message): Some (but not all) targets in this export were already defined.
Targets Defined: Qt::Core
Targets not yet defined: Qt::CorePrivate

@BBertschinger
Copy link

Same Issue here, but instead I tried to build w. Qt6.

But this seems to be a different problem.
You can build and use the PCL-Viewer without Qt if needed.

Just set the corresponding build Option:

-DWITH_QT:BOOL=OFF

@Harsh19012003
Copy link

I can verify it crashes with same issue
I am running ubuntu 22.04 and installed pcl for testing of autonomous vehicle project with pcl 1.12.1......

ig no one has solved it yet.......
waiting for support from community

@haixuanwo
Copy link

The following api should be a call abandoned interface, you can use the new interface@senicko

abandoned:
pcl::PointCloudpcl::PointXYZRGB::Ptr cloud;
pcl::visualization::CloudViewer viewer("Simple Cloud Viewer");
viewer.showCloud(cloud);

new:
pcl::visualization::PCLVisualizer vis2 ("visualize");
vis2.addPointCloud (cloud);
vis2.spin ();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants