Opened 8 years ago

Closed 8 years ago

#1008 closed defect (fixed)

Reversing a Collection via slicing causes a segfault

Reported by: Tristan Croll Owned by: Tom Goddard
Priority: major Milestone:
Component: Core Version:
Keywords: Cc:
Blocked By: Blocking:
Notify when closed: Platform: all
Project: ChimeraX

Description

With a single atomic model loaded:

m = session.models.list()[0]
r = m.residues
r2 = m[::-1]
r2.names # segfault

The below fixes it:

diff --git a/src/core/atomic/molarray.py b/src/core/atomic/molarray.py
index 9a1d8bb..a3fcfcf 100644
--- a/src/core/atomic/molarray.py
+++ b/src/core/atomic/molarray.py
@@ -103,7 +103,8 @@ class Collection(State):
             pointers = numpy.empty((0,), cptr)
         elif isinstance(items, numpy.ndarray) and items.dtype == numpy.uintp:
             # C++ pointers array
-            pointers = items
+            pointers = numpy.empty(len(items), numpy.uintp)
+            pointers[:] = items
         else:
             # presume iterable of objects of the object_class
             try:

Change History (1)

comment:1 by Tom Goddard, 8 years ago

Resolution: fixed
Status: assignedclosed

Fixed.

The C++ code that gets attributes from arrays of pointers assumes those pointer arrays are contiguous. The slicing code for Collection was not assuring a contiguous array, so I made it create a contiguous array.

Note: See TracTickets for help on using tickets.