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

vtkSmartPointer<vtkPolyDataMapper>::New () return NULL #3484

Closed
leihui6 opened this issue Nov 24, 2019 · 8 comments
Closed

vtkSmartPointer<vtkPolyDataMapper>::New () return NULL #3484

leihui6 opened this issue Nov 24, 2019 · 8 comments

Comments

@leihui6
Copy link

leihui6 commented Nov 24, 2019

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.

@Liudyan
Copy link

Liudyan commented Feb 27, 2020

I solved the problem, you should add the
#include <vtkAutoInit.h>
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

@kunaltyagi
Copy link
Member

kunaltyagi commented Feb 27, 2020

Are the changes in PCL code or your code?

@Liudyan
Copy link

Liudyan commented Feb 27, 2020

Are the changes in PCL code or your code?
in test_shapes.cpp ( PCL Version: 1.9.1 X64 release ), just add
#include <vtkAutoInit.h>
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 }

@kunaltyagi
Copy link
Member

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.

@SergioRAgostinho
Copy link
Member

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.

@leihui6
Copy link
Author

leihui6 commented Feb 27, 2020

Are the changes in PCL code or your code?
in test_shapes.cpp ( PCL Version: 1.9.1 X64 release ), just add
#include <vtkAutoInit.h>
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.

@taketwo taketwo removed the needs: author reply Specify why not closed/merged yet label Feb 29, 2020
@larshg
Copy link
Contributor

larshg commented May 14, 2020

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.

@DingLei627
Copy link

Are the changes in PCL code or your code?
in test_shapes.cpp ( PCL Version: 1.9.1 X64 release ), just add
#include <vtkAutoInit.h>
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.

Hi, you add these code in which header file? And you add the opennGL in VS linker, how to do that?

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

7 participants