Giter Site home page Giter Site logo

Comments (11)

BigRoy avatar BigRoy commented on August 11, 2024

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 QApplication.instance() right? (Edit: I see this actually came up in the link too)

Anyway, I wonder why this hasn't been a problem for any other hosts (even those without Qt). Am I missing something obvious?

from core.

jasperges avatar jasperges commented on August 11, 2024

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 C++ object was gone.
Would it hurt to make sure a reference is kept to the QApplication?

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 tools.lib.application.

from core.

tokejepsen avatar tokejepsen commented on August 11, 2024

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.

from core.

BigRoy avatar BigRoy commented on August 11, 2024

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 module.window is basically a dangling pointer to nothingness. Making this crash resolved with a simple "check" whether QWindow is still valid.

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 if statement.

@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?

from core.

tokejepsen avatar tokejepsen commented on August 11, 2024

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.

Yeah, you are right!

Does adding this help?

The module.window point to an invalid window, but I'm not sure how to figure out whether its valid or not, cause its the QApplication instance that is gone and not the window instance.
Will investigate this.

from core.

tokejepsen avatar tokejepsen commented on August 11, 2024

This issue can be solved by introducing an existing_app variable on the lib module. Then we can query whether its a new application or an existing one.

But I would also like to figure out, why do we need to close and delete the existing window in those lines?
I tried to show the context manager multiple times in Nuke, and didnt get any duplicated windows.

from core.

tokejepsen avatar tokejepsen commented on August 11, 2024

I tried to show the context manager multiple times in Nuke, and didnt get any duplicated windows.

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.

from core.

mottosso avatar mottosso commented on August 11, 2024

Does holding onto the instance of a QApplication solve this issue? What if it's being held onto at the module-level, like tools are, from the lib.application() call?

core/avalon/tools/lib.py

Lines 21 to 31 in ace0c79

def application():
app = QtWidgets.QApplication.instance()
if not app:
print("Starting new QApplication..")
app = QtWidgets.QApplication(sys.argv)
yield app
app.exec_()
else:
print("Using existing QApplication..")
yield app

E.g.

def application():
  app = module._app or QApplication()

  ...

  module._app = app

With an underscore, to prevent accessing it from the outside.

from core.

tokejepsen avatar tokejepsen commented on August 11, 2024

Does holding onto the instance of a QApplication solve this issue? What if it's being held onto at the module-level, like tools are, from the lib.application() call?

I have tried to store the QApplication on the module level, but on the second try of launching the tool becomes unresponsive and I dont get why that is?

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()

Untitled_ Jan 28, 2020 9_55 AM

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.

from core.

mottosso avatar mottosso commented on August 11, 2024

I would take a step back. Ensure you can get a QPushButton running first. Off the top of my head, it looks like the QApplication isn't running on that second try. What you're seeing is what would happen if you didn't start one to begin with.

from core.

tokejepsen avatar tokejepsen commented on August 11, 2024

Ok, I seem to be able to hold onto the QApplication at the module level but when holding onto the window then I get the above unresponsive dialog that takes the webserver down with it.

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.