When building OpenGL toolkits using GLFW and Cython, I came across a very, very strange problem. I created the following pxd file (quite large, so I used it):
https://gist.github.com/1441970
Next I have this wrapping code (extremely simplified to show the essence of the problem).
pygrafix.window module:
from pygrafix.c_headers.glfw cimport *
And this main file:
from pygrafix import window window = window.Window(800, 600) print("TEST LOCATION TWO") def on_scroll(window, pos): print(pos) window.set_mouse_scroll_callback(on_scroll) while window.is_open(): window.flip()
And finally, I compile it as follows:
cython.py -o pygrafix/window.cy.c pygrafix/window.pyx gcc -O3 -shared -DGLFW_DLL -IC:\Python27\include pygrafix/window.cy.c -o pygrafix/window.pyd -LC:\Python27\libs -lpython27 -lgfwldll
But it crashes (windows say that there was an error in the program). When I comment on the glfwSetMouseWheelCallback
call, it does not crash. The strange thing is, if I compile with -O0 , it does not crash and works as it should! . I am completely puzzled by this. I checked the C code that cython prints out and it looks fine. _mouse_scroll_callback_handler
is of type void (*)(int)
, and a pointer to it passes well to glfw.
Other oddities:
- This only happens with
glfwSetMouseWheelCallback
(or, at least for me), and not with glwSetMousePosCallback, for example. - If I pass NULL to
glfwSetMouseWheelCallback
, no problem. - Even if a failure occurs, TEST LOCATION ONE is still printed, but TEST LOCATION TWO does not.
- It also works if I compile with -O3 -pg
What could be the reason for this and what would be the correct fix (without compiling with -O0)?
Other little things:
I use Windows 7 64 bit, GLFW 2.7.2, Cython 0.15.1, GCC 4.6.1 in MinGW and CPython 2.7.2.
source share