client: Fix crash on shutdown on Mesa driver

On Wayland, then the mesa driver is in use, calling
eglDestroySurface() while OpenGL commands are being
executed may crash. While this means the driver does
not operate by the specs in this case, the driver is
so popular that it makes sense to work around it.

To work around this, we read-lock the surface while
rendering and wait for a write-lock before we destroy
the EGL surface.

[ChangeLog][QtWaylandClient] Fixed a crash on shutdown that could
happen with some graphics-heavy applications when running on Mesa
drivers.

Pick-to: 6.3
Fixes: QTBUG-92249
Change-Id: I8b8461066cc9f948dc44ddeeddaa6e7d92b76f04
Reviewed-by: Liang Qi <liang.qi@qt.io>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2021-11-10 13:18:30 +01:00
parent 8b3de53ee6
commit 46991c54c8
2 changed files with 15 additions and 1 deletions

View File

@ -77,6 +77,7 @@ QWaylandWindow::QWaylandWindow(QWindow *window, QWaylandDisplay *display)
: QPlatformWindow(window)
, mDisplay(display)
, mResizeAfterSwap(qEnvironmentVariableIsSet("QT_WAYLAND_RESIZE_AFTER_SWAP"))
, mSurfaceLock(QReadWriteLock::Recursive)
{
{
bool ok;
@ -235,6 +236,16 @@ bool QWaylandWindow::shouldCreateSubSurface() const
return QPlatformWindow::parent() != nullptr;
}
void QWaylandWindow::beginFrame()
{
mSurfaceLock.lockForRead();
}
void QWaylandWindow::endFrame()
{
mSurfaceLock.unlock();
}
void QWaylandWindow::reset()
{
delete mShellSurface;
@ -242,10 +253,10 @@ void QWaylandWindow::reset()
delete mSubSurfaceWindow;
mSubSurfaceWindow = nullptr;
invalidateSurface();
if (mSurface) {
emit wlSurfaceDestroyed();
QWriteLocker lock(&mSurfaceLock);
invalidateSurface();
mSurface.reset();
}

View File

@ -233,6 +233,9 @@ public:
void setXdgActivationToken(const QString &token);
void requestXdgActivationToken(uint serial);
void beginFrame();
void endFrame();
public slots:
void applyConfigure();