GNOME Bugzilla – Bug 132058
gtkgl bus error on constructor to gtk.gl.Area
Last modified: 2005-08-22 12:44:20 UTC
Obtained a bus error from the following code: >>> import gtk.gl >>> glarea = gtk.gl.Area((gtk.gl.RGBA, gtk.gl.DOUBLEBUFFER, gtk.gl.DEPTH_SIZE, 1)) Bus error Here is a stack trace from gdb: Program received signal EXC_BAD_ACCESS, Could not access memory. 0x006a0ee0 in g_type_check_instance_cast () (gdb) where
+ Trace 43389
This code works on Linux, obviously
Rick, if you're interested in helping fix this, try taking a look at the code pointed out by frame 1, which is _wrap_gtk_gl_area_share_new at gtkgl.override:94. I'm not sure any of the more active developers has easy access to a Mac to be able to reproduce this, but the error could be obvious (it *seems* like we're calling g_type_check_instance_cast() on a freed pointer, to me) and if so "patches welcome" <wink>.
Okay, I'm doing my best to track this down, even though I've never done anything quite like this before, so forgive me if a lot of what I say is stating the obvious. The relevant lines of code are in gtkgl.c here: if (!pygobject_check(py_share, &PyGtkGLArea_Type)) { if ( pygobject_get(py_share) != NULL ) share = GTK_GL_AREA(pygobject_get(py_share)); } else if (py_share != Py_None) { PyErr_SetString(PyExc_TypeError, "share must be a GtkGLArea or None"); return -1; } in the function _wrap_gtk_gl_area_share_new() (which is the initializer of the gtk.gl.Area object). the pygobject_check() macro seems to be the culprit here. In pygobject.h, this is defined as: #define pygobject_check(v,base) (PyObject_TypeCheck(v,base)) where the latter macro is defined in <python2.3/object.h>, and almost certainly isn't the problem. So, it would appear that the code is crashing because py_share doesn't point to anything, right? py_share is initialized to Py_None, and is then assigned to some value via PyArg_ParseTuple. Given this clue, I decided to play around with the constructor. Recall that the test code was >>> import gtk.gl >>> glarea = gtk.gl.Area((gtk.gl.RGBA, gtk.gl.DOUBLEBUFFER, gtk.gl.DEPTH_SIZE, 1)) which defaults to py_share (the second argument) = None. If, instead, I pass in 0: >>> import gtk.gl >>> glarea = gtk.gl.Area((gtk.gl.RGBA, gtk.gl.DOUBLEBUFFER, gtk.gl.DEPTH_SIZE, 1),0) the code doesn't give a bus error! Can someone who knows more about this than I suggest a patch?
ISTM that the line if (!pygobject_check(py_share, &PyGtkGLArea_Type)) { is incorrect, and that it should in fact be if (pygobject_check(py_share, &PyGtkGLArea_Type)) { since PyObject_Typecheck returns 1 when the argument is of the specified type and 0 if not [*]. Otherwise the check for Py_None in the following clause is bogus, right? Can you give that a try and let me know? [*] http://www.python.org/doc/current/ext/node33.html
And if so, this error is not Mac-related at all, so update the OS fields accordingly :-)
Christian, your suggestion to change the line if (!pygobject_check(py_share, &PyGtkGLArea_Type)) { to if (pygobject_check(py_share, &PyGtkGLArea_Type)) { worked. In fact, it gave an error to my "workaround code" where I set py_share to 0, telling me that py_share had to be either None or a glarea. I changed the OS of this bug to "All". Can anyone confirm that this patch would work on other platforms, and explain why it wasn't a bug there>
Possibly because nobody else has tested this before. Johan, can you check this in and close this one for us? Thanks.
Okay, I tried the patch on Linux (RH9.0), using Python 2.3.2, pygtk 2.0, and PyOpenGL-2.0.1.07. I made the test script a little bit more complex: try: glarea = gtk.gl.Area((gtk.gl.RGBA, gtk.gl.DOUBLEBUFFER, gtk.gl.DEPTH_SIZE, 1),None) print "Second arg = None succeeded" except: print "Second arg = None failed" try: glarea = gtk.gl.Area((gtk.gl.RGBA, gtk.gl.DOUBLEBUFFER, gtk.gl.DEPTH_SIZE, 1)) print "No second arg succeeded" except: print "No second arg failed" try: glarea = gtk.gl.Area((gtk.gl.RGBA, gtk.gl.DOUBLEBUFFER, gtk.gl.DEPTH_SIZE, 1),0) print "Second arg = zero succeeded" except: print "Second arg = zero failed" Before the patch, all three Area() calls succeeded, which I believe is incorrect (the last one should fail, since you need to supply either None or nothing or a GLArea, but not the integer 0). After the patch, the first two succeeded and the third failed, which I believe is correct. I believe that this patch can be safely committed.
gtkgl area code has been removed from the current cvs code which makes this bug having no more sense.
Can we put the code back into the CVS archive? I'm currently maintaining a project that uses these widgets, and will be glad to maintain the codebase if necessary. I realize that the smart thing to do is to migrate my code from glarea to glext, but that's a headache for another month right now. Plus, the glext code wasn't in the standard bindings either, last time I checked.
Would it be practical for you to maintain this code as a separate package? That way you're not tied to the availability of the PyGTK team and in general will have more flexibility with releases and changes.
Sounds ok to me. I'll ask to close the bug once the binding will be moved (probably this week end).