[vtkusers] Call for Examples!

Kenneth Porter shiva at sewingwitch.com
Tue Jan 5 08:43:18 EST 2010


--On Tuesday, January 05, 2010 9:13 AM +0100 Bryn Lloyd 
<blloyd at vision.ee.ethz.ch> wrote:

> Regarding example:
> http://www.cmake.org/Wiki/Create_a_surface_from_Unorganized_Points
>
> The reason for the segmentation fault is that the vtkPoints is created in
> the function and returned. The smartpointer reduced its count to zero and
> deletes it.
>
> I fixed the example. Now it first creates the vtkPoints. The actual
> values are inserted in the readPoints function.

An equally-valid (but more exception-safe) solution is to have the old 
readPoints return a vtkSmartPointer<vtkPoints>, and change points in main 
to a smart pointer. This passes ownership of the object created in 
readPoints back to main, and prevents the reference count from dropping to 
zero. See my comment at the end of this section:

<http://www.cmake.org/Wiki/Smart_Pointers#Returning_a_Smart_Pointer>





More information about the vtkusers mailing list