[vtkusers] smart pointer as member in class
Cory Quammen
cory.quammen at kitware.com
Tue Sep 22 22:10:51 EDT 2015
Hi,
I assume you are callling init() before setdata()? If not, that's obviously
the problem.
There shouldn't be any memory free'd until your object is deleted, so make
sure your object is still around when you call setdata().
Thanks,
Cory
On Tue, Sep 22, 2015 at 4:13 PM, Feng Xing <snakexf at gmail.com> wrote:
> Hello everyone,
>
> I tried to define a class, its number is vtkSmartPointer<vtkDoubleArray>
> data. It is allocated in one member function (init()), and given values in
> another member function(setdata()). I get always segmentation errors. Il
> seems that data in setdata() function is not allocated or (freed?). If I
> put data->SetComponents in init(). All works well. Where is the problem?
> The pointer?
>
> Thank you very much.
>
> The code is similar like this
>
> class VisuVTK
>
> private:
> vtkSmartPointer<vtkDoubleArray> data;
>
> public:
>
> init(){
> data = vtkSmartPointer<vtkDoubleArray>::New();
> data->SetNumberOfComponents(1); // size of component in tuple is 1
> data->SetNumberOfTuples(Ncell); // size of data
> };
>
> setdata(){
> for(int i=0;i<Ncell;i++){
> data->SetComponent(i,0,1.0); }
> };
>
> end class
>
> Feng Xing
> Postdoc in France
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
--
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150922/4fd1f03d/attachment.html>
More information about the vtkusers
mailing list