Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6970129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:40:14+00:00 2026-05-27T16:40:14+00:00

While making an OpenGL toolkit using GLFW and Cython I stumbled upon a very,

  • 0

While making an OpenGL toolkit using GLFW and Cython I stumbled upon a very, very weird issue. I created the following file pxd file (quite large, so I gisted it):

https://gist.github.com/1441970

Next I have this wrapping code (extremely simplified to show the core of the problem).

pygrafix.window module:

from pygrafix.c_headers.glfw cimport * # this is the pxd file

glfwInit()

_window = None

cdef void _mouse_scroll_callback_handler(int pos):
    if _window._mouse_scroll_callback:
        _window._mouse_scroll_callback(_window, pos)

cdef class Window:
    cdef public object _mouse_scroll_callback

    def __cinit__(self):
        global _window
        self._mouse_scroll_callback = None

        _window = self

    def __init__(self, int width = 0, int height = 0):
        glfwOpenWindow(width, height, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)
        glfwSetMouseWheelCallback(<GLFWmousewheelfun> &_mouse_scroll_callback_handler)
        print("TEST LOCATION ONE")

    def is_open(self):
        return glfwGetWindowParam(GLFW_OPENED)

    def flip(self):
        glfwSwapBuffers()

    def set_mouse_scroll_callback(self, func):
        self._mouse_scroll_callback = func

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 like this:

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 says there was an error in the program). When I comment out the call to glfwSetMouseWheelCallback it doesn’t crash.
The strange thing is, if I compile with -O0 it doesn’t crash and works as it should! I am completely baffled by this. I checked the C code that cython outputs, and it looks ok.
_mouse_scroll_callback_handler is of the type void (*)(int), and the pointer to it gets passed nicely into glfw.

Other oddities:

  • This only happens with glfwSetMouseWheelCallback (or at least to me), not with glwSetMousePosCallback for example.
  • If I pass NULL to glfwSetMouseWheelCallback, there is no problem.
  • Even if there is a crash, TEST LOCATION ONE still gets printed, but TEST LOCATION TWO doesn’t.
  • It also works if I compile with -O3 -pg

What could possibly be the cause of this, and what would be the correct fix (without having to compile at -O0)?


Other trivia:

I’m using Windows 7 64 bit, GLFW 2.7.2, Cython 0.15.1, GCC 4.6.1 under MinGW and CPython 2.7.2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:40:15+00:00Added an answer on May 27, 2026 at 4:40 pm

    I finally found the solution. The problem was that I didn’t add __stdcall in Cython to the callback functions, nor did I know it supported this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm interested in making the mouse cursor invisible while using opengl + glut, how
While making a little Pong game in C++ OpenGL, I decided it'd be fun
I stumbled on a way to crash excel in Workbook_Open while making an .xla
I'm starting with Ruby, and while making some test samples, I've stumbled against an
I'm having trouble with making a subdomain to my Windows computer while using AJP
I'm making a relatively simple OpenGL ES based iPhone game. While testing on the
So I'm making something in openGL using SDL. I'm about to take a long
I'm making a Minecraft clone as my very first OpenGL project and am stuck
While making my code, i ran into a strange problem. I hold 1 file
I'm making a program using openGL with transparent objects in it, so obviously I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.