From 9beed6c55f1109eda880f13e63cc577d613d1d1a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Katharina=20Kr=C3=A4mer?= <kkraemer4@uni-koblenz.de>
Date: Mon, 3 May 2021 13:51:51 +0200
Subject: [PATCH] [#7] replaced queue priority array by a std::vector

---
 src/vkcv/Context.cpp | 14 ++++++++------
 src/vkcv/Context.hpp |  2 +-
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/vkcv/Context.cpp b/src/vkcv/Context.cpp
index 48ce7c3e..e4950161 100644
--- a/src/vkcv/Context.cpp
+++ b/src/vkcv/Context.cpp
@@ -87,8 +87,12 @@ namespace vkcv {
 			throw std::runtime_error("The requested device extensions are not supported by the physical device!");
 		}
 
+		//vector to define the queue priorities
+		std::vector<float> qPriorities;
+		qPriorities.resize(queueCount, 1.f); // all queues have the same priorities
+
 		// create required queues
-		std::vector<vk::DeviceQueueCreateInfo> qCreateInfos = getQueueCreateInfos(physicalDevice, queueCount, queueFlags);
+		std::vector<vk::DeviceQueueCreateInfo> qCreateInfos = getQueueCreateInfos(physicalDevice, queueCount, qPriorities,queueFlags);
 
 		vk::DeviceCreateInfo deviceCreateInfo(
 			vk::DeviceCreateFlags(),
@@ -200,7 +204,7 @@ namespace vkcv {
 	/// <param name="queueCount">The amount of queues to be created</param>
 	/// <param name="queueFlags">The abilities which have to be supported by any created queue</param>
 	/// <returns></returns>
-	std::vector<vk::DeviceQueueCreateInfo> Context::getQueueCreateInfos(vk::PhysicalDevice& physicalDevice, uint32_t queueCount, std::vector<vk::QueueFlagBits>& queueFlags) {
+	std::vector<vk::DeviceQueueCreateInfo> Context::getQueueCreateInfos(vk::PhysicalDevice& physicalDevice, uint32_t queueCount,std::vector<float> &qPriorities, std::vector<vk::QueueFlagBits>& queueFlags) {
 		std::vector<vk::DeviceQueueCreateInfo> queueCreateInfos;
 		std::vector<vk::QueueFamilyProperties> qFamilyProperties = physicalDevice.getQueueFamilyProperties();
 		std::vector<vk::QueueFamilyProperties> qFamilyCandidates;
@@ -218,14 +222,12 @@ namespace vkcv {
 
 		uint32_t create = queueCount;
 		for (int i = 0; i < qFamilyCandidates.size() && create > 0; i++) {
-			const int maxCreatableQueues = std::min(create, qFamilyCandidates[i].queueCount);
-			float* qPriorities = new float[maxCreatableQueues];		// TO CHECK: this seems to solve validation layer errors but the array pointer will not be deleted
-			std::fill_n(qPriorities, maxCreatableQueues, 1.f);		// all queues have the same priorities
+			const int maxCreatableQueues = std::min(create, qFamilyCandidates[i].queueCount);		
 			vk::DeviceQueueCreateInfo qCreateInfo(
 				vk::DeviceQueueCreateFlags(),
 				i,
 				maxCreatableQueues,
-				qPriorities
+				qPriorities.data()
 			);
 			queueCreateInfos.push_back(qCreateInfo);
 			create -= maxCreatableQueues;
diff --git a/src/vkcv/Context.hpp b/src/vkcv/Context.hpp
index e27c766b..779c5b85 100644
--- a/src/vkcv/Context.hpp
+++ b/src/vkcv/Context.hpp
@@ -38,7 +38,7 @@ namespace vkcv {
 		static std::vector<const char*> getRequiredExtensions();
 		static vk::PhysicalDevice pickPhysicalDevice(vk::Instance& instance);
 		static int deviceScore(const vk::PhysicalDevice &physicalDevice);
-		static std::vector<vk::DeviceQueueCreateInfo> getQueueCreateInfos(vk::PhysicalDevice& physicalDevice, uint32_t queueCount, std::vector<vk::QueueFlagBits> &queueFlags);
+		static std::vector<vk::DeviceQueueCreateInfo> getQueueCreateInfos(vk::PhysicalDevice& physicalDevice, uint32_t queueCount, std::vector<float>& qPriorities, std::vector<vk::QueueFlagBits> &queueFlags);
 	};
 
 }
-- 
GitLab