# Segfault when converting a mesh entity iterator to a list (in Python)

Asked by Maximilian Albert on 2013-03-13

The following code snippet results in a segfault:

==>
from dolfin import *
mesh = BoxMesh(0, 0, 0, 1, 1, 1, 1, 1, 1)
c = list(cells(mesh))[0]
print c.volume() # --> segfault
<==

On the other hand, the following works fine:

==>
from dolfin import *
mesh = BoxMesh(0, 0, 0, 1, 1, 1, 1, 1, 1)
for c in cells(mesh):
print c.volume()
<==

The problem seems to be the conversion of cells(mesh) to a list (since calling any other method on 'c' in the first example also results in a segfault). Is this a bug, or is it simply not recommended to do this? Is there another, robust way of converting cells(mesh) to a list?

## Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
2013-03-13
Last query:
2013-03-13
2013-03-13
 Johan Hake (johan-hake) said on 2013-03-13: #1

On 03/13/2013 07:01 PM, Maximilian Albert wrote:
> New question #224186 on DOLFIN:
>
> The following code snippet results in a segfault:
>
> ==>
> from dolfin import *
> mesh = BoxMesh(0, 0, 0, 1, 1, 1, 1, 1, 1)
> c = list(cells(mesh))[0]
> print c.volume() # --> segfault
> <==
>
> On the other hand, the following works fine:
>
> ==>
> from dolfin import *
> mesh = BoxMesh(0, 0, 0, 1, 1, 1, 1, 1, 1)
> for c in cells(mesh):
> print c.volume()
> <==
>
> The problem seems to be the conversion of cells(mesh) to a list (since calling any other method on 'c' in the first example also results in a segfault). Is this a bug, or is it simply not recommended to do this? Is there another, robust way of converting cells(mesh) to a list?

This is a bug and is fixed in trunk. Thanks for reporting :)

Johan

 Maximilian Albert (cilix) said on 2013-03-13: #2

Thanks! I seem to have the right touch with reporting bugs that are already fixed. ;-)

 Maximilian Albert (cilix) said on 2013-03-13: #3

Thanks Johan Hake, that solved my question.

 Johan Hake (johan-hake) said on 2013-03-13: #4

On 03/13/2013 09:26 PM, Maximilian Albert wrote:
> Question #224186 on DOLFIN changed:
>