diff --git a/src/wayland/autotests/client/test_wayland_surface.cpp b/src/wayland/autotests/client/test_wayland_surface.cpp index 404501494f..669288274d 100644 --- a/src/wayland/autotests/client/test_wayland_surface.cpp +++ b/src/wayland/autotests/client/test_wayland_surface.cpp @@ -178,6 +178,8 @@ void TestWaylandSurface::testStaticAccessor() QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(serverSurfaceCreated.isValid()); + QVERIFY(!KWayland::Server::SurfaceInterface::get(nullptr)); + QVERIFY(!KWayland::Server::SurfaceInterface::get(1, nullptr)); QVERIFY(KWayland::Client::Surface::all().isEmpty()); KWayland::Client::Surface *s1 = m_compositor->createSurface(); QVERIFY(s1->isValid()); @@ -226,6 +228,11 @@ void TestWaylandSurface::testStaticAccessor() delete s1; QVERIFY(KWayland::Client::Surface::all().isEmpty()); QVERIFY(!KWayland::Client::Surface::get(nullptr)); + QSignalSpy unboundSpy(serverSurface1, &KWayland::Server::Resource::unbound); + QVERIFY(unboundSpy.isValid()); + QVERIFY(unboundSpy.wait()); + QVERIFY(!KWayland::Server::SurfaceInterface::get(nullptr)); + QVERIFY(!KWayland::Server::SurfaceInterface::get(1, nullptr)); } void TestWaylandSurface::testDamage() diff --git a/src/wayland/server/resource_p.h b/src/wayland/server/resource_p.h index 4ecda0bdc2..34ca5c5b6e 100644 --- a/src/wayland/server/resource_p.h +++ b/src/wayland/server/resource_p.h @@ -44,6 +44,9 @@ public: static ResourceDerived *get(wl_resource *native) { static_assert(std::is_base_of::value, "ResourceDerived must be derived from Resource"); + if (!native) { + return nullptr; + } auto it = std::find_if(s_allResources.constBegin(), s_allResources.constEnd(), [native](Private *p) { return p->resource == native;