-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bizarre error possibly related to unreleased bindings. #74
Comments
I did a quick patch to the I called |
I read the docs again and found a tidbit that might be related:
This is almost certainly relevant. The QGLContext is created in C++. When we call I called This QStandardItem is newly created. The QGLContext is old (created roughly 50,000 QStandardItems ago). The QGLContext's parent is a widget which I know is still alive; but calling I have a feeling that the purported QGLContext I get when querying the binding for the QStandardItem is a dead object. It was refcounted to zero by Python and freed a long time ago, but the memory at that address still looks like a Python wrapper for a QGLContext. This feeling was only strengthened after this experience: I was entering Python commands into PDB. I had a list containing that QGLContext. I called As a tentative fix, I tried changing |
Here's something else that's going on. If I call After the second call, |
Okay, I think I'm getting somewhere. When I change the parent of the QGLWidget, it creates a new QGLContext for itself. The BindingManager still has the old QGLContext registered with its wrapper. The QGLWidget's wrapper still has the old QGLContext wrapper in its At some point later, the old QGLContext wrapper gets dealloc'd, which calls a series of functions that eventually calls I haven't figured out exactly when the old QGLContext wrapper gets deallocated, but I know that in the time between the QGLWidget creating a new context for itself and the old context wrapper being deallocated, there is an invalid binding registered in BindingManager. Because of the invalid binding, when a C++ QStandardItem is created at the address formerly occupied by a QGLContext, stupid errors like the one at the beginning of the issue will occur. My tentative fix to If a binding is already registered for a C++ pointer when By changing |
At last, a minimal test case that reproduces the issue. (At least, it does for PySide 1.2.2, Python 2.7.10 64-bit on Windows 7...)
|
I am also getting a similar error, though on a different method: AttributeError: 'PySide.QtOpenGL.QGLContext' object has no attribute 'moveToThread' (this is on linux) is there any quick fix that would enable us to call the desired methods? |
The "quick fix" - if you can even call it that - is to ensure that you never call The bug persists even for other objects, so the "quick fix" does not fix anything. The bug depends on this sequence of events:
|
I'd like to send a PR with a fix for this, but I'm honestly not sure which commit to base it on. Or if you want, I'll just send a PR on the shiboken2 repo. |
Sending the PR to shiboken2 would be best as that's where development is happening now |
I wrote a bit about this in the other repo, but you can ignore all of those insane ramblings in favor of this condensed version:
(PySide 1.2.2, Python 2.7 for 64-bit Windows)
Rarely, I experience this completely inexplicable error nestled within my logging code, miles away from anything that uses a QGLContext:
What the fuck, right?
After reading through the baseobject and binding generation code for a bit, the best explanation I can come up with is that a binding is not being released from
BindingManager
. Huh?BindingManager
keeps track of the bindings that go from C++ objects (void *) to Python objects (SbkObject *). This serves several purposes, but only one of them seems to be of interest:QStandardItem.setData
is a virtual function. When I instantiate a QStandardItem on the Python side, the C++ side will create a CppWrapper - a C++ subclass of QStandardItem which will dispatch its virtual functions through the Python wrapper associated with it throughBindingManager
. This is meant to allow me to subclass QStandardItem in Python. Any C++ code that invokes the virtual function will call the overrides implemented on the Python side, thanks to the CppWrapper.QStandardItem.setData
is called by the implementation ofQStandardItem.setForeground
.I think what is happening is that there is a binding in
BindingManager
, mapping the C++ QGLContext to the Python QGLContext, that is not being released. Because it is not released, a QStandardItem CppWrapper will later be created at the same memory address, and theBindingManager
will then contain a mapping that says, roughly,CppWrapper<QStandardItem> -> SbkObject<QGLContext>
Thus, thanks to the CppWrapper,
QStandardItem.setForeground
will try to callQGLContext.setData
, resulting in an AttributeError.I won't speculate on why it isn't being released. I don't think I understand the problem well enough to say anything.
I haven't been able to create a minimal test case that reproduces the error. What I have been able to do is modify my application code in such a way that instead of getting the error rarely, I can now get it >90% of the times the app is launched.
The text was updated successfully, but these errors were encountered: