Quantcast

VtkIdList and SetArray, allocation error

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

VtkIdList and SetArray, allocation error

foufara
Hi All,

First, thank you Kitware for VTK ! It is really great ! A real pleasure to use it in my everyday work.

I'm using vtk 7.1.0 with Python bindings on a Mac with Sierra (OS 10.12).

Since quite recently (VTK 7.0 ?), vtkIdList has a new method SetArray which should allow us to link it to an numpy array.
I suppose that this should enable us to create large vtkIdList more efficiently than when using InsertNextId or another similar method (like when using numpy_support for vtkDataArrays)

So I tried something like this :

a=np.arange(10)
l=vtk.vtkIdList()
l.SetArray(a,len(a))
print l.GetNumberOfIds()
for i in range(l.GetNumberOfIds()):
    print i,l.GetId(i)

It seems to work fine, but when I quit python, I get en error message saying

"Python(13731,0x7fff9714b3c0) malloc: *** error for object 0x7fe9611a4c80: pointer being freed was not allocated"

And I really don't know how to prevent this.
I tried to call the Allocate or the SetNumberOfIds methods first. But this does not change anything.

Besides, the error does not occur everytime.

Can you help me on that ? Try that code on another OS (several times) ?

Thank you for your help !

Raphaël

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: VtkIdList and SetArray, allocation error

Andy Bauer
I haven't looked at the vtkIdList::SetArray() method but I wonder if this has to do with bad memory use or freeing. Maybe vtkIdList assumes that  the memory will not be freed and in your script Python is garbage collecting the memory. Not 100% sure on this but that's where I'd first look.

On Fri, Apr 28, 2017 at 1:53 PM, foufara via vtkusers <[hidden email]> wrote:
Hi All,

First, thank you Kitware for VTK ! It is really great ! A real pleasure to
use it in my everyday work.

I'm using vtk 7.1.0 with Python bindings on a Mac with Sierra (OS 10.12).

Since quite recently (VTK 7.0 ?), vtkIdList has a new method SetArray which
should allow us to link it to an numpy array.
I suppose that this should enable us to create large vtkIdList more
efficiently than when using InsertNextId or another similar method (like
when using numpy_support for vtkDataArrays)

So I tried something like this :

a=np.arange(10)
l=vtk.vtkIdList()
l.SetArray(a,len(a))
print l.GetNumberOfIds()
for i in range(l.GetNumberOfIds()):
    print i,l.GetId(i)

It seems to work fine, but when I quit python, I get en error message saying

"Python(13731,0x7fff9714b3c0) malloc: *** error for object 0x7fe9611a4c80:
pointer being freed was not allocated"

And I really don't know how to prevent this.
I tried to call the Allocate or the SetNumberOfIds methods first. But this
does not change anything.

Besides, the error does not occur everytime.

Can you help me on that ? Try that code on another OS (several times) ?

Thank you for your help !

Raphaël





--
View this message in context: http://vtk.1045678.n5.nabble.com/VtkIdList-and-SetArray-allocation-error-tp5743017.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
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


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: VtkIdList and SetArray, allocation error

foufara
Thank you Andy for that quick answer.
As I understand the message, yes this has to do with a bad usage of memory.
But the message is odd. It says that my vtkIdList has been allocated at the time of freeing it, even though it seemed to work well giving me the rights Ids…How can it be ?
And the error occurs at the time of quitting Python. So the memory has to be freed at that time…
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: VtkIdList and SetArray, allocation error

Aron Helser
Yes, I'd suspect the memory is getting freed twice - that's what "pointer being freed was not allocated" probably means.
It's likely that both vtkIdList and numpy think they own the memory, and can free it. 

I'm not finding a reference on how to fix this issue, however. Could be this blob series might suggest a better approach:

HTH,
Aron

On Fri, Apr 28, 2017 at 2:35 PM, foufara via vtkusers <[hidden email]> wrote:
Thank you Andy for that quick answer.
As I understand the message, yes this has to do with a bad usage of memory.
But the message is odd. It says that my vtkIdList has been allocated at the
time of freeing it, even though it seemed to work well giving me the rights
Ids…How can it be ?
And the error occurs at the time of quitting Python. So the memory has to be
freed at that time…



--
View this message in context: http://vtk.1045678.n5.nabble.com/VtkIdList-and-SetArray-allocation-error-tp5743017p5743019.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
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


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: VtkIdList and SetArray, allocation error

foufara
Hi Aron, thanks for your answer.
Thank you for the link about numpy_interface. I was precisely wondering what it was for.
However it does not directly solve my problem with vtkIdList.
About the memory being freed twice, I tried a del my_vtkIdList before the end of the script, with the idea that if vtk freed the memory first, then it would not raise any issue (maybe numpy then). But it does not change anything. The del statement raises the same error…

Thank you anyway !

Anyone else has an idea ?
Should I move this topic to the dev section ?

Have a good day
Loading...