-
Notifications
You must be signed in to change notification settings - Fork 49
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
Make sure the QApplication doesn't get garbage collected #514
Comments
I believe it should never get garbage collected by default as it creates a singleton internally? That's also why you can retrieve it with Anyway, I wonder why this hasn't been a problem for any other hosts (even those without Qt). Am I missing something obvious? |
To be honest: I have no idea if it should or should not get garbage collected. The fact is, it somehow was. Or to be precise: the underlying Have there been any other hosts (apart from Blender) who don't have Qt? For the Blender integration it isn't a problem, because it creates a QApplication by itself, so it doesn't rely on the code in |
I can confirm that I'm getting the same issue with the Photoshop integration. Every second opening of any of the tools, will crash the web server without any error messages. For example commenting out https://github.com/getavalon/core/blob/master/avalon/tools/contextmanager/app.py#L218-L222 will allow me to open the context app more than once. |
Actually, isn't that the opposite behavior? This actually sounds logical to me. Whenever the last Qt application's window closes I believe by default the QApplication instance is supposed to "close off" which likely leaves the Window object in an invalid state. Basically meaning the Window would be destroyed meaning whatever is stored in Does adding this help? if module.window: It seems in the current code we're trying to close a QWindow that doesn't actually exist anymore. I'm not sure that's the valid way to check whether the QObject still exists in memory, but I'm expecting it would be. This however hints that it could be more complicated than just the @tokejepsen the other way around is to force the QApplication to persist even after closing the last window: app.setQuitOnLastWindowClosed(False) Does that also fix the crash? |
Yeah, you are right!
The |
This issue can be solved by introducing an But I would also like to figure out, why do we need to close and delete the existing window in those lines? |
Tried in Maya, and its seems like it does make duplicate windows there, so will need those lines of code. Not sure why it does not make duplicates in Nuke. |
- Each tool gets destroyed on close. - Each tool gets raised if there is an existing window. - All tools' windows gets activated.
Does holding onto the instance of a Lines 21 to 31 in ace0c79
E.g. def application():
app = module._app or QApplication()
...
module._app = app With an underscore, to prevent accessing it from the outside. |
I have tried to store the def show(parent=None):
try:
module.window.show()
except (RuntimeError, AttributeError):
# RuntimeError if the module.window C++ object has been deleted.
# AttributeError if the module.window is None.
with lib.application() as app:
window = Window(parent)
window.show()
window.setStyleSheet(style.load_stylesheet())
module.window = window
module.qapp = app
window.activateWindow() This is tested with the upcoming webserver, which is the base for the Photoshop integration. Its running the tools standalone, similar to how the TV Paint integration would which is the original issue here. |
I would take a step back. Ensure you can get a |
Ok, I seem to be able to hold onto the |
Following up on this 'bug', reported on the Avalon Gitter.
The
show()
function for the tools creates aQApplication
if needed (viatools.lib.application()
). The problem however is that theQApplication
created in this way will possibly be garbage collected which in turn causes issues with for examplemodule.window.close()
.This makes this 'convenience helper' not so convenient anymore. I think we should fix it, so the
QApplication
will never be garbage collected. Else it doesn't serve it's purpose and an integration is better off creating theQApplication
by itself.The text was updated successfully, but these errors were encountered: