﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	blockedby	blocking	notify_on_close	platform	project
1096	Bug in c_array_property()	Tristan Croll	Eric Pettersen	"This is rather odd. Using the molc API, I have a class `Proper_Dihedral` which contains the following:

{{{
    atoms = c_property('proper_dihedral_atoms', cptr, 4, astype=_atoms, read_only=True,
        doc = 'Atoms making up this dihedral. Read only.')
}}}

This works exactly as expected to start with, but if I close one model and attempt to use it on the new one it fails silently by returning an empty `Atoms` (`Collection.__init__` just receives an empty array). I've added a reporter to my C++ side which shows it is returning the correct pointers in every case, and furthermore if I replace the above with the functionally-equivalent:
{{{
    @property
    def atoms(self):
        f = c_function('proper_dihedral_atoms',
            args=(ctypes.c_void_p, ctypes.c_size_t, ctypes.c_void_p))
        ret = numpy.empty(4, cptr)
        f(self._c_pointer_ref, 1, pointer(ret))
        return _atoms(ret)
}}}

... then all is fine again, through opening and closing at least half a dozen models. Likewise, if I force `c_property` to use `c_varlen_property()` by doing:

{{{
    @property
    def four(self):
        return 4

    atoms = c_property('proper_dihedral_atoms', cptr, 'four', astype=_atoms, read_only=True,
        doc = 'Atoms making up this dihedral. Read only.')

}}}

... then everything works. Changing line 136 of `molc.py` from 
{{{
                return astype(v)
}}}

to
 
{{{
                return astype(v.copy())
}}}

seems to fix it. Not entirely sure why it arises in the first place, though."	defect	closed	major		Core		fixed		Tom Goddard				all	ChimeraX
