﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	blockedby	blocking	notify_on_close	platform	project
1373	"""TypeError: Require contiguous 3x4 array"" when Drawing has only one instance"	Tristan Croll	Tom Goddard	"Seems to be another change in the `Drawing` API that I'm struggling to come to terms with. In ISOLDE I'm now getting errors that crash the graphics loop any time I do something that creates exactly one instance of one of my restraint indicators (traceback below). Tracing it back using my dihedral restraints indicator as an example, the core of the problem seems to arise in the following snippet (from line 736 of `drawing.py`):

{{{
        pos = self.positions
        use_instancing = (len(pos) > 1 or pos.shift_and_scale_array() is not None)
        spos = self.parent.get_scene_positions(displayed_only=True) if use_instancing else self.get_scene_positions(displayed_only=True)
        for p in spos:
            # TODO: Optimize this to use same 4x4 opengl matrix each call.
            renderer.set_model_matrix(p)
}}}

If I have a look at the offending drawing:

{{{
from chimerax.isolde import session_extensions as sx

prm = sx.get_proper_dihedral_restraint_mgr(session.isolde.selected_model)

d = prm._ring_drawing

dpos = d.get_scene_positions(displayed_only=True)

dpos[0].matrix.data.c_contiguous
Out[5]: False

dpos[0].matrix.data.f_contiguous
Out[6]: True

ppos = d.parent.get_scene_positions(displayed_only=True)

ppos[0].matrix.data.c_contiguous
Out[8]: True
}}}

... so the drawing and parent have different row ordering. In the cases leading to the problem, `use_instancing` should be True (since `len(pos)` is 1 and `pos.shift_and_scale_array()` returns `None`). 

That's about as far as I've gotten. The parent is a `Model` subclass which never modifies its own position - just handles the redrawing triggers, selection etc.. Just to be explicit about it, everything works exactly as expected when the drawing has 0 or >1 positions. 

{{{
Traceback (most recent call last):
File ""/home/tic20/apps/chimerax/lib/python3.6/site-packages/chimerax/core/updateloop.py"", line 72, in draw_new_frame
view.draw(check_for_changes = False)
File ""/home/tic20/apps/chimerax/lib/python3.6/site-packages/chimerax/core/graphics/view.py"", line 159, in draw
self._draw_scene(camera, drawings)
File ""/home/tic20/apps/chimerax/lib/python3.6/site-packages/chimerax/core/graphics/view.py"", line 217, in _draw_scene
draw_opaque(r, opaque_drawings)
File ""/home/tic20/apps/chimerax/lib/python3.6/site-packages/chimerax/core/graphics/drawing.py"", line 1355, in draw_opaque
_draw_multiple(drawings, renderer, Drawing.OPAQUE_DRAW_PASS)
File ""/home/tic20/apps/chimerax/lib/python3.6/site-packages/chimerax/core/graphics/drawing.py"", line 1366, in _draw_multiple
d.draw(renderer, draw_pass)
File ""/home/tic20/apps/chimerax/lib/python3.6/site-packages/chimerax/core/graphics/drawing.py"", line 683, in draw
self.draw_self(renderer, draw_pass)
File ""/home/tic20/apps/chimerax/lib/python3.6/site-packages/chimerax/core/graphics/drawing.py"", line 690, in draw_self
self._draw_geometry(renderer, opaque_only = any_transp)
File ""/home/tic20/apps/chimerax/lib/python3.6/site-packages/chimerax/core/graphics/drawing.py"", line 741, in _draw_geometry
renderer.set_model_matrix(p)
File ""/home/tic20/apps/chimerax/lib/python3.6/site-packages/chimerax/core/graphics/opengl.py"", line 608, in set_model_matrix
if ((model_matrix.is_identity() and cmm.is_identity())
File ""/home/tic20/apps/chimerax/lib/python3.6/site-packages/chimerax/core/geometry/place.py"", line 298, in is_identity
or _geometry.is_identity_matrix(self.matrix, tolerance))
TypeError: Require contiguous 3x4 array
}}}"	defect	closed	critical		Graphics		fixed						all	ChimeraX
