After installing Yosemite, I had to upgrade numpy, PyOpenGL, etc.
Now, a previously-working program is giving me the following stack trace:
file "latebind.pyx", line 44, in OpenGL_accelerate.latebind.Curry.__call__ (src/latebind.c:1201)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/OpenGL/GL/VERSION/GL_1_5.py", line 89, in glBufferData
return baseOperation( target, size, data, usage )
File "latebind.pyx", line 32, in OpenGL_accelerate.latebind.LateBind.__call__ (src/latebind.c:989)
File "wrapper.pyx", line 314, in OpenGL_accelerate.wrapper.Wrapper.__call__ (src/wrapper.c:6505)
File "wrapper.pyx", line 311, in OpenGL_accelerate.wrapper.Wrapper.__call__ (src/wrapper.c:6439)
ctypes.ArgumentError: ("argument 3: <class 'OpenGL.error.CopyError'>: from_param received a non-contiguous array! []", (GL_ARRAY_BUFFER, 0, array([],
dtype=[('time', '<f8'), ('data', [('cluster_index', '<i4'), ('delta_diag_out', '<f8')])]), GL_STREAM_DRAW))
It looks like PyOpenGL wants my array to be contiguous. Looking at the source in numpy_formathandler.pyx in PyOpenGL:
if not PyArray_ISCARRAY( instance ):
raise CopyError(
"""from_param received a non-contiguous array! %s"""%(
working,
)
)
And PyArray_ISCARRAY(arr) "Evaluates true if the data area of arr is C-style contiguous, and PyArray_ISBEHAVED (arr) is true." Whereby "PyArray_ISBEHAVED(arr) Evalutes true if the data area of arr is aligned and writeable and in machine byte-order according to its descriptor."
However, the flags
attribute of the array that was pushed to OpenGL is:
C_CONTIGUOUS : True
F_CONTIGUOUS : True
OWNDATA : False
WRITEABLE : True
ALIGNED : False
UPDATEIFCOPY : False
Perhaps I need to align the array? But using numpy.require
with requirements={'ALIGNED': True}
doesn't seem to work.
I looked at the changes in numpy 1.9, which indicate:
There is a new compile time environment variable NPY_RELAXED_STRIDES_CHECKING. If this variable is set to 1, then numpy will consider more arrays to be C- or F-contiguous – for example, it becomes possible to have a column vector which is considered both C- and F-contiguous simultaneously. The new definition is more accurate, allows for faster code that makes fewer unnecessary copies, and simplifies numpy’s code internally. However, it may also break third-party libraries that make too-strong assumptions about the stride values of C- and F-contiguous arrays. (It is also currently known that this breaks Cython code using memoryviews, which will be fixed in Cython.) THIS WILL BECOME THE DEFAULT IN A FUTURE RELEASE, SO PLEASE TEST YOUR CODE NOW AGAINST NUMPY BUILT WITH:
NPY_RELAXED_STRIDES_CHECKING=1 python setup.py install
You can check whether NPY_RELAXED_STRIDES_CHECKING is in effect by running:
np.ones((10, 1), order="C").flags.f_contiguous
This will be True if relaxed strides checking is enabled, and False otherwise. The typical problem we’ve seen so far is C code that works with C-contiguous arrays, and assumes that the itemsize can be accessed by looking at the last element in the PyArray_STRIDES(arr) array. When relaxed strides are in effect, this is not true (and in fact, it never was true in some corner cases). Instead, use PyArray_ITEMSIZE(arr).
However, np.ones((10, 1), order="C").flags.f_contiguous
is False on my system. So I'm stumped. What changed that is causing opengl to think that the arrays I'm sending it are not contiguous and aligned? Is there a way to align an array by force?
This is probably related to this bug in numpy 1.9 to which no one is assigned: https://github.com/numpy/numpy/issues/5224
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With