Pcl: vtkSmartPointer<vtkPolyDataMapper>::New () return NULL

Created on 24 Nov 2019  路  7Comments  路  Source: PointCloudLibrary/pcl


vtkSmartPointer::New () Failed

My Environment

  • Operating System and version: Win10 Pro 10.0.18362 Build 18362
  • Compiler: MSVC2017 64bit
  • PCL Version: 1.9.1

Context

addText3D and addSphere() crashed (maybe more).
When drawing 3d text on screen, I find the addText3D does not work! Then I find the key is
vtkSmartPointer<vtkPolyDataMapper> textMapper = vtkSmartPointer<vtkPolyDataMapper>::New (); failed. I thought maybe it only crash by this way or my code is wrong. However, It also failed when I try to run example code from test_shapes.cpp.
at line 34:p.addSphere<PointXYZ> (cloud->points[0], 1, 0.0, 1.0, 0.0);, it crashed again, and I find the reason is same as addText3D.New() function always returns NULL, so next line textMapper->SetInputConnection (textSource->GetOutputPort ()); crashed due to empty pointier.


Expected Behavior


Current Behavior



If I do not change pcl_visualizer.hpp, It crashed just because of empty pointer.

Code to Reproduce


For better understand, below are part of my code:

pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
viewer->setBackgroundColor(0, 0, 0);
viewer->addCoordinateSystem(1.0, "first");
string show_text = "distance:";
//... get point_vec(vector<pcl::PointXYZ>)
viewer->addText3D(show_text , point_vec[i], 1, 1, 1, 1);

Possible Solution



Because of the problem of empty pointer, I judge the NULL before next code, like this

vtkSmartPointer<vtkPolyDataMapper> textMapper = vtkSmartPointer<vtkPolyDataMapper>::New ();
if (!textMapper)
{
     return false;
}
textMapper->SetInputConnection (textSource->GetOutputPort ());

The good news is yeah it works, but ... you know, there is no text3d text showing on screen but the text2d is OK(test_shapes.cpp). Now I have no idea how to deal with it.

bug visualization windows

All 7 comments

I solved the problem, you should add the

include

VTK_MODULE_INIT(vtkRenderingOpenGL); //if render backen is OpenGL2, it should changes to vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);

and add the opengl32.lib in the linker

Are the changes in PCL code or your code?

Are the changes in PCL code or your code?
in test_shapes.cpp ( PCL Version: 1.9.1 X64 release ), just add

include

VTK_MODULE_INIT(vtkRenderingOpenGL); //if render backen is OpenGL2, it should changes to vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
add the opengl32.lib in the Vs linker

vtkSmartPointer textMapper = vtkSmartPointer::New ()

textMapper is
vtkSmartPointerBase = {Object=0x000001fb129923a0 {ReferenceCount={Atomic=2 } WeakPointers=0x0000000000000000 {???} } }

if not
textMapper is
vtkSmartPointerBase = {Object=0x0000000000000000 }

I'm sorry @liudongminghaha It's still not clear to me. If the change is in PCL, please submit a PR, else the solution so others can benefit from it.

This problem is usually caused when then VTK definitions are not passed in. It is very likely that this was caused my wrongly constructed CMake file.

Are the changes in PCL code or your code?
in test_shapes.cpp ( PCL Version: 1.9.1 X64 release ), just add

include

VTK_MODULE_INIT(vtkRenderingOpenGL); //if render backen is OpenGL2, it should changes to vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
add the opengl32.lib in the Vs linker

vtkSmartPointer textMapper = vtkSmartPointer::New ()

textMapper is
vtkSmartPointerBase = {Object=0x000001fb129923a0 {ReferenceCount={Atomic=2 } WeakPointers=0x0000000000000000 {???} } }

if not
textMapper is
vtkSmartPointerBase = {Object=0x0000000000000000 }

Thanks for your help very much!! it works well as you said.
there is the header of my test code:,

#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);

finally, I could see a 3D text displaying on the screen, that is cool!
yeah, I think it is a bug, and maybe only a few people will use this feature(display 3D text). but now, your solution fixes it, maybe you could PR or @ PCL developers to solve it in the next version.

I think @SergioRAgostinho is right.
The VTK_MODULE_INIT is part of the preprocessor definitions, which probably isn't correctly set.

So its not a bug in PCL, but user error when setting projects up. Another vote for better/updated install tutorials.

Lets close it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SunBlack picture SunBlack  路  3Comments

Micalson picture Micalson  路  4Comments

mgarbade picture mgarbade  路  3Comments

rmsalinas picture rmsalinas  路  3Comments

BjoB picture BjoB  路  4Comments