From 2d87d4204016946e0b1d03cb41830686c84acc7f Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 4 Oct 2023 21:45:32 +0200 Subject: [PATCH] rhi: Fix intro doc snippet with Vulkan The QVulkanInstance must outlive the QRhi (if Vulkan is used). Otherwise subtle problems may pop up upon application exit. Change-Id: Ia7074c7f53633d51cf3bbdcc84e7f578214d9648 Reviewed-by: Laszlo Agocs (cherry picked from commit 1d019de6b7090ea6c973f7e9fa780259a455ce98) Reviewed-by: Qt Cherry-pick Bot --- src/gui/doc/snippets/rhioffscreen/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/doc/snippets/rhioffscreen/main.cpp b/src/gui/doc/snippets/rhioffscreen/main.cpp index 217b07dcdad..1db1a8f59ab 100644 --- a/src/gui/doc/snippets/rhioffscreen/main.cpp +++ b/src/gui/doc/snippets/rhioffscreen/main.cpp @@ -11,6 +11,9 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); +#if QT_CONFIG(vulkan) + QVulkanInstance inst; +#endif std::unique_ptr rhi; #if defined(Q_OS_WIN) QRhiD3D12InitParams params; @@ -19,7 +22,6 @@ int main(int argc, char **argv) QRhiMetalInitParams params; rhi.reset(QRhi::create(QRhi::Metal, ¶ms)); #elif QT_CONFIG(vulkan) - QVulkanInstance inst; inst.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions()); if (inst.create()) { QRhiVulkanInitParams params;