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

[tools] pcl_visualizer segfaults when selecting double channel for coloring #6186

Open
themightyoarfish opened this issue Nov 27, 2024 · 3 comments

Comments

@themightyoarfish
Copy link
Contributor

Describe the bug

When a pointcloud has an 8 F field, selecting this channel for display segfaults with this report:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x13fb99816)
  * frame #0: 0x0000000108aa4efc libvtkCommonCore-9.3.dylib`vtkAOSDataArrayTemplate<float>::SetArray(float*, long long, int, int) + 36
    frame #1: 0x0000000100492524 libpcl_visualization.1.14.dylib`pcl::visualization::PointCloudColorHandlerGenericField<pcl::PCLPointCloud2>::getColor() const + 696
    frame #2: 0x000000010047e2e8 libpcl_visualization.1.14.dylib`pcl::visualization::PCLVisualizerInteractorStyle::OnKeyDown() + 2428
    frame #3: 0x000000010286ce88 libvtkRenderingCore-9.3.1.dylib`vtkInteractorStyle::ProcessEvents(vtkObject*, unsigned long, void*, void*) + 4008
    frame #4: 0x0000000108a0613c libvtkCommonCore-9.3.dylib`vtkCallbackCommand::Execute(vtkObject*, unsigned long, void*) + 44
    frame #5: 0x0000000108b1ca98 libvtkCommonCore-9.3.dylib`vtkSubjectHelper::InvokeEvent(unsigned long, void*, vtkObject*) + 1232
    frame #6: 0x0000000101dce8f0 libvtkRenderingOpenGL2-9.3.dylib`-[vtkCocoaGLView invokeVTKKeyEvent:cocoaEvent:] + 608
    frame #7: 0x0000000198822fc8 AppKit`-[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 316
    frame #8: 0x0000000198822cbc AppKit`-[NSWindow(NSEventRouting) sendEvent:] + 284
    frame #9: 0x000000019903aeb0 AppKit`-[NSApplication(NSEventRouting) sendEvent:] + 2360
    frame #10: 0x0000000198c4889c AppKit`-[NSApplication _handleEvent:] + 60
    frame #11: 0x00000001986eeb08 AppKit`-[NSApplication run] + 520
    frame #12: 0x000000010001cc48 pcl_viewer`main + 17620
    frame #13: 0x0000000194768274 dyld`start + 2840

Context

The point cloud was made from a custom point type:

struct PointXYZIT {
  PCL_ADD_POINT4D
  PCL_ADD_INTENSITY
  double time;
  PCL_MAKE_ALIGNED_OPERATOR_NEW
};

…

POINT_CLOUD_REGISTER_POINT_STRUCT(
    autocrane::PointXYZIT,
    (float, x, x)(float, y, y)(float, z, z)(float, intensity, intensity)(double,
                                                                         time,
                                                                         time))

Expected behavior

Viewer displays the double field correctly

Current Behavior

Viewer crashes

To Reproduce

  1. Build pcl d257a89130386c3356fba8ba0f04e8e2089704f3.
  2. run pcl_viewer on attached point cloud
  3. press key 6 to visualize time channel
  4. cry

Your Environment (please complete the following information):

  • OS: macos 15.1.1 ARM
  • Compiler: Apple Clang 16.0.0
  • PCL Version d257a89

Possible Solution

Fix vtk display, or error when double fields are used

Additional context

2024-11-27T13_32_45_939Z.pcd.zip

@themightyoarfish themightyoarfish added kind: bug Type of issue status: triage Labels incomplete labels Nov 27, 2024
@themightyoarfish
Copy link
Contributor Author

actually not sure if this is related to the double type, it happens too with an std::uint64_t type. maybe its just the 6th channel thats the issue?

@themightyoarfish
Copy link
Contributor Author

Inside PointCloudColorHandlerGenericField::getColor() it seems to assume that the field value fits inside a float.

float field_data
…
    // Color every point
    for (vtkIdType cp = 0; cp < nr_points; ++cp)
    {
      const std::uint8_t* pt_data = reinterpret_cast<const std::uint8_t*> (&(*cloud_)[cp]);
      memcpy (&field_data, pt_data + fields_[field_idx_].offset, pcl::getFieldSize (fields_[field_idx_].datatype));

      if (!std::isfinite (field_data))
        continue;

      colors[j] = field_data;
      j++;
    }

@mvieth
Copy link
Member

mvieth commented Nov 28, 2024

Hi, yes seems like that currently only works with a float type. Even types that have the same size as a float (like uint32_t) would not work since they are not cast properly. I guess we should at least add a check whether the field is of type float or not. Making it actually work with other types would be more difficult and need a switch-case. The passthrough filter has a similar situation; it makes sure that the field is a float before computing.

@mvieth mvieth added module: visualization and removed status: triage Labels incomplete labels Nov 28, 2024
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

2 participants