Skip to content

Commit

Permalink
[usdviewq] Fix GL error spew on shutdown
Browse files Browse the repository at this point in the history
Closing the usdview window (via the [X] button, or Alt+F4) resulted in a bunch of GL errors when using PySide2. The errors stem from the GL context being destroyed before the renderer in the stage view widget is shutdown. This change of behavior from PySide to PySide2 resulted in the stageView widget being destroyed before the aboutToQuit handler was invoked. The fix reworks the way usdview shuts down.
- Hoist the main window widget into a class that implements closeEvent, which triggers shutdown of the stage (and stageView).
- Connect closeAllWindows to the File>Quit action, which in turn triggers the main window's closeEvent. Closing the application via the window leads to the same shutdown process.
- Remove existing handler registration to the aboutToQuit signal.

(Internal change: 2055246)
  • Loading branch information
rajabala authored and pixar-oss committed Apr 6, 2020
1 parent 6728adf commit ef43aff
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions pxr/usdImaging/usdviewq/appController.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,22 @@ def blocked(self):

return self._count > 0

class MainWindow(QtWidgets.QMainWindow):
"This class exists to simplify and streamline the shutdown process."
"The application may be closed via the File menu, or by closing the main"
"window, both of which result in the same behavior."
def __init__(self, closeFunc, printCloseTiming):
super(MainWindow, self).__init__(None) # no parent widget
self._closeFunc = closeFunc
self._printCloseTiming = printCloseTiming

def closeEvent(self, event):
self._closeFunc()

with Timer() as t:
self.close() # Close the MainWindow widget.
if self._printCloseTiming:
t.PrintTime('tear down the UI')

class AppController(QtCore.QObject):

Expand Down Expand Up @@ -405,7 +421,8 @@ def __init__(self, parserData, resolverContextFn):
# start listening for style-related changes.
self._setStyleSheetUsingState()

self._mainWindow = QtWidgets.QMainWindow(None)
self._mainWindow = MainWindow(lambda: self._cleanAndClose(),
self._printTiming)
self._ui = Ui_MainWindow()
self._ui.setupUi(self._mainWindow)

Expand Down Expand Up @@ -845,9 +862,9 @@ def __init__(self, parserData, resolverContextFn):
self._toggleStop)

# Setup quit actions to ensure _cleanAndClose is only invoked once.
self._ui.actionQuit.triggered.connect(QtWidgets.QApplication.instance().quit)

QtWidgets.QApplication.instance().aboutToQuit.connect(self._cleanAndClose)
# Don't register a handler for the 'aboutToQuit' signal,
# since the mainWindow's closeEvent handler triggers _cleanAndClose.
self._ui.actionQuit.triggered.connect(QtWidgets.QApplication.instance().closeAllWindows)

self._ui.actionReopen_Stage.triggered.connect(self._reopenStage)

Expand Down Expand Up @@ -2476,7 +2493,8 @@ def GrabViewportShot(self):
# File handling functionality =============================================

def _cleanAndClose(self):

# This function is called by the main window's closeEvent handler.

self._settings2.save()

# If the current path widget is focused when closing usdview, it can
Expand All @@ -2502,15 +2520,9 @@ def _cleanAndClose(self):
if self._timer.isActive():
self._timer.stop()

# Close the stage.
# Close stage and release renderer resources (if applicable).
self._closeStage()

# Tear down the UI window.
with Timer() as t:
self._mainWindow.close()
if self._printTiming:
t.PrintTime('tear down the UI')

def _openFile(self):
extensions = Sdf.FileFormat.FindAllFileFormatExtensions()
builtInFiles = lambda f: f.startswith(".usd")
Expand Down

0 comments on commit ef43aff

Please sign in to comment.