[wayland] Fix cleanup handling on tear down

ASAN righly complained: we need to delete our Wayland objects before
we destroy the internal client connection. Solved by better setting
parent relationships in the QPA plugin and correctly delete objects
in destroy of internal client connection.
This commit is contained in:
Martin Gräßlin 2015-11-10 11:35:00 +01:00
parent 51b44f4a87
commit 8175562a7a
3 changed files with 14 additions and 6 deletions

View file

@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KWayland/Client/output.h> #include <KWayland/Client/output.h>
#include <KWayland/Client/registry.h> #include <KWayland/Client/registry.h>
#include <KWayland/Client/shell.h> #include <KWayland/Client/shell.h>
#include <KWayland/Client/surface.h>
#include <KWayland/Server/clientconnection.h> #include <KWayland/Server/clientconnection.h>
#include <QCoreApplication> #include <QCoreApplication>
@ -112,8 +113,8 @@ QPlatformWindow *Integration::createPlatformWindow(QWindow *window) const
return new QPlatformWindow(window); return new QPlatformWindow(window);
} else { } else {
// don't set window as parent, cause infinite recursion in PlasmaQuick::Dialog // don't set window as parent, cause infinite recursion in PlasmaQuick::Dialog
auto surface = c->createSurface(); auto surface = c->createSurface(c);
return new Window(window, surface, s->createSurface(surface), this); return new Window(window, surface, s->createSurface(surface, surface), this);
} }
} }
@ -196,7 +197,7 @@ KWayland::Client::Compositor *Integration::compositor() const
auto registry = waylandServer()->internalClientRegistry(); auto registry = waylandServer()->internalClientRegistry();
const auto c = registry->interface(Registry::Interface::Compositor); const auto c = registry->interface(Registry::Interface::Compositor);
if (c.name != 0u) { if (c.name != 0u) {
const_cast<Integration*>(this)->m_compositor = registry->createCompositor(c.name, c.version); const_cast<Integration*>(this)->m_compositor = registry->createCompositor(c.name, c.version, registry);
} }
} }
return m_compositor; return m_compositor;
@ -209,7 +210,7 @@ KWayland::Client::Shell *Integration::shell() const
auto registry = waylandServer()->internalClientRegistry(); auto registry = waylandServer()->internalClientRegistry();
const auto s = registry->interface(Registry::Interface::Shell); const auto s = registry->interface(Registry::Interface::Shell);
if (s.name != 0u) { if (s.name != 0u) {
const_cast<Integration*>(this)->m_shell = registry->createShell(s.name, s.version); const_cast<Integration*>(this)->m_shell = registry->createShell(s.name, s.version, registry);
} }
} }
return m_shell; return m_shell;

View file

@ -43,6 +43,8 @@ Window::Window(QWindow *window, KWayland::Client::Surface *surface, KWayland::Cl
, m_windowId(++s_windowId) , m_windowId(++s_windowId)
, m_integration(integration) , m_integration(integration)
{ {
QObject::connect(m_surface, &QObject::destroyed, window, [this] { m_surface = nullptr;});
QObject::connect(m_shellSurface, &QObject::destroyed, window, [this] { m_shellSurface = nullptr;});
waylandServer()->internalClientConection()->flush(); waylandServer()->internalClientConection()->flush();
} }
@ -103,8 +105,10 @@ void Window::unmap()
if (m_shellClient) { if (m_shellClient) {
m_shellClient->setInternalFramebufferObject(QSharedPointer<QOpenGLFramebufferObject>()); m_shellClient->setInternalFramebufferObject(QSharedPointer<QOpenGLFramebufferObject>());
} }
m_surface->attachBuffer(KWayland::Client::Buffer::Ptr()); if (m_surface) {
m_surface->commit(KWayland::Client::Surface::CommitFlag::None); m_surface->attachBuffer(KWayland::Client::Buffer::Ptr());
m_surface->commit(KWayland::Client::Surface::CommitFlag::None);
}
if (waylandServer()->internalClientConection()) { if (waylandServer()->internalClientConection()) {
waylandServer()->internalClientConection()->flush(); waylandServer()->internalClientConection()->flush();
} }

View file

@ -29,6 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KWayland/Client/connection_thread.h> #include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/event_queue.h> #include <KWayland/Client/event_queue.h>
#include <KWayland/Client/registry.h> #include <KWayland/Client/registry.h>
#include <KWayland/Client/shm_pool.h>
#include <KWayland/Client/surface.h> #include <KWayland/Client/surface.h>
// Server // Server
#include <KWayland/Server/compositor_interface.h> #include <KWayland/Server/compositor_interface.h>
@ -75,6 +76,8 @@ WaylandServer::~WaylandServer() = default;
void WaylandServer::destroyInternalConnection() void WaylandServer::destroyInternalConnection()
{ {
if (m_internalConnection.client) { if (m_internalConnection.client) {
delete m_internalConnection.registry;
delete m_internalConnection.shm;
dispatch(); dispatch();
m_internalConnection.client->deleteLater(); m_internalConnection.client->deleteLater();
m_internalConnection.clientThread->quit(); m_internalConnection.clientThread->quit();