From 306360c922bfe8ee38034fe975a88d76ca4e59bf Mon Sep 17 00:00:00 2001
From: Jacki <jacki@thejackimonster.de>
Date: Mon, 16 Sep 2024 22:44:14 +0200
Subject: [PATCH] Fix and improve string formatting

Signed-off-by: Jacki <jacki@thejackimonster.de>
---
 .../src/vkcv/asset/asset_loader.cpp           | 35 ++++++++++---------
 modules/gui/src/vkcv/gui/GUI.cpp              |  3 +-
 modules/scene/src/vkcv/scene/Scene.cpp        |  3 +-
 .../src/vkcv/shader/Compiler.cpp              |  9 +++--
 .../src/vkcv/shader/GLSLCompiler.cpp          |  6 ++--
 .../src/vkcv/shader/HLSLCompiler.cpp          |  6 ++--
 .../src/vkcv/shader/SlangCompiler.cpp         |  2 +-
 src/vkcv/Core.cpp                             |  2 +-
 src/vkcv/DescriptorSetManager.cpp             |  2 +-
 src/vkcv/FeatureManager.cpp                   | 10 ++++--
 src/vkcv/File.cpp                             | 21 +++++++----
 src/vkcv/SwapchainManager.cpp                 |  8 +++--
 src/vkcv/TypeGuard.cpp                        | 24 ++++++++-----
 13 files changed, 80 insertions(+), 51 deletions(-)

diff --git a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp
index 3f32d61e..5c868b73 100644
--- a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp
+++ b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp
@@ -17,7 +17,7 @@ namespace vkcv::asset {
 	 * @param path	The path to the file that was responsible for the exception
 	 */
 	static void recurseExceptionPrint(const std::exception& e, const std::string &path) {
-		vkcv_log(LogLevel::ERROR, "Loading file %s: %s", path.c_str(), e.what());
+		vkcv_log(LogLevel::ERROR, "Loading file %s: %s", path.string().c_str(), e.what());
 		
 		try {
 			std::rethrow_if_nested(e);
@@ -554,7 +554,7 @@ namespace vkcv::asset {
 	
 		// file has to contain at least one mesh
 		if (sceneObjects.meshes.empty()) {
-			vkcv_log(LogLevel::ERROR, "No meshes found! (%s)", path.c_str());
+			vkcv_log(LogLevel::ERROR, "No meshes found! (%s)", path.string().c_str());
 			return ASSET_ERROR;
 		} else {
 			scene.meshes.reserve(sceneObjects.meshes.size());
@@ -565,7 +565,7 @@ namespace vkcv::asset {
 				
 				if (loadVertexGroups(sceneObjects.meshes[i], sceneObjects, scene, mesh) != ASSET_SUCCESS) {
 					vkcv_log(LogLevel::ERROR, "Failed to load vertex groups of '%s'! (%s)",
-							 mesh.name.c_str(), path.c_str());
+							 mesh.name.c_str(), path.string().c_str());
 					return ASSET_ERROR;
 				}
 				
@@ -625,7 +625,8 @@ namespace vkcv::asset {
 		}
 		
 		if (sceneObjects.samplers.empty()) {
-			vkcv_log(LogLevel::WARNING, "No samplers found! (%s)", path.c_str());
+			vkcv_log(LogLevel::WARNING, "No samplers found! (%s)", 
+							 path.string().c_str());
 		} else {
 			scene.samplers.reserve(sceneObjects.samplers.size());
 			
@@ -635,7 +636,8 @@ namespace vkcv::asset {
 		}
 		
 		if (sceneObjects.textures.empty()) {
-			vkcv_log(LogLevel::WARNING, "No textures found! (%s)", path.c_str());
+			vkcv_log(LogLevel::WARNING, "No textures found! (%s)",
+							 path.string().c_str());
 		} else {
 			scene.textures.reserve(sceneObjects.textures.size());
 			
@@ -647,7 +649,7 @@ namespace vkcv::asset {
 				} else
 				if (static_cast<size_t>(textureObject.sampler) >= scene.samplers.size()) {
 					vkcv_log(LogLevel::ERROR, "Sampler of texture '%s' missing (%s)",
-							 textureObject.name.c_str(), path.c_str());
+							 textureObject.name.c_str(), path.string().c_str());
 					return ASSET_ERROR;
 				} else {
 					texture.sampler = textureObject.sampler;
@@ -656,7 +658,7 @@ namespace vkcv::asset {
 				if ((textureObject.source < 0) ||
 					(static_cast<size_t>(textureObject.source) >= sceneObjects.images.size())) {
 					vkcv_log(LogLevel::ERROR, "Failed to load texture '%s' (%s)",
-							 textureObject.name.c_str(), path.c_str());
+							 textureObject.name.c_str(), path.string().c_str());
 					return ASSET_ERROR;
 				}
 				
@@ -679,7 +681,8 @@ namespace vkcv::asset {
 		}
 		
 		if (sceneObjects.materials.empty()) {
-			vkcv_log(LogLevel::WARNING, "No materials found! (%s)", path.c_str());
+			vkcv_log(LogLevel::WARNING, "No materials found! (%s)",
+							 path.string().c_str());
 		} else {
 			scene.materials.reserve(sceneObjects.materials.size());
 			
@@ -746,7 +749,7 @@ namespace vkcv::asset {
 		
 		if (!data) {
 			vkcv_log(LogLevel::ERROR, "Texture could not be loaded from '%s'",
-					 texture.path.c_str());
+							 texture.path.string().c_str());
 			
 			texture.width = 0;
 			texture.height = 0;
@@ -777,7 +780,7 @@ namespace vkcv::asset {
 				const int result = loadTextureData(scene.textures[material.baseColor]);
 				if (ASSET_SUCCESS != result) {
 					vkcv_log(LogLevel::ERROR, "Failed loading baseColor texture of mesh '%s'",
-							 mesh.name.c_str())
+									 mesh.name.c_str())
 					return result;
 				}
 			}
@@ -786,7 +789,7 @@ namespace vkcv::asset {
 				const int result = loadTextureData(scene.textures[material.metalRough]);
 				if (ASSET_SUCCESS != result) {
 					vkcv_log(LogLevel::ERROR, "Failed loading metalRough texture of mesh '%s'",
-							 mesh.name.c_str())
+									 mesh.name.c_str())
 					return result;
 				}
 			}
@@ -795,7 +798,7 @@ namespace vkcv::asset {
 				const int result = loadTextureData(scene.textures[material.normal]);
 				if (ASSET_SUCCESS != result) {
 					vkcv_log(LogLevel::ERROR, "Failed loading normal texture of mesh '%s'",
-							 mesh.name.c_str())
+									 mesh.name.c_str())
 					return result;
 				}
 			}
@@ -804,7 +807,7 @@ namespace vkcv::asset {
 				const int result = loadTextureData(scene.textures[material.occlusion]);
 				if (ASSET_SUCCESS != result) {
 					vkcv_log(LogLevel::ERROR, "Failed loading occlusion texture of mesh '%s'",
-							 mesh.name.c_str())
+									 mesh.name.c_str())
 					return result;
 				}
 			}
@@ -813,7 +816,7 @@ namespace vkcv::asset {
 				const int result = loadTextureData(scene.textures[material.emissive]);
 				if (ASSET_SUCCESS != result) {
 					vkcv_log(LogLevel::ERROR, "Failed loading emissive texture of mesh '%s'",
-							 mesh.name.c_str())
+									 mesh.name.c_str())
 					return result;
 				}
 			}
@@ -828,7 +831,7 @@ namespace vkcv::asset {
 		
 		if (result != ASSET_SUCCESS) {
 			vkcv_log(LogLevel::ERROR, "Loading scene failed '%s'",
-					 path.c_str());
+							 path.string().c_str());
 			return result;
 		}
 		
@@ -843,7 +846,7 @@ namespace vkcv::asset {
 			
 			if (result != ASSET_SUCCESS) {
 				vkcv_log(LogLevel::ERROR, "Loading mesh with index %d failed '%s'",
-						 static_cast<int>(i), path.c_str());
+						 static_cast<int>(i), path.string().c_str());
 				return result;
 			}
 		}
diff --git a/modules/gui/src/vkcv/gui/GUI.cpp b/modules/gui/src/vkcv/gui/GUI.cpp
index 7978b10a..df30951a 100644
--- a/modules/gui/src/vkcv/gui/GUI.cpp
+++ b/modules/gui/src/vkcv/gui/GUI.cpp
@@ -15,7 +15,8 @@ namespace vkcv::gui {
 		
 		const auto result = vk::Result(resultCode);
 		
-		vkcv_log(LogLevel::ERROR, "ImGui has a problem with Vulkan! (%s)", vk::to_string(result).c_str());
+		vkcv_log(LogLevel::ERROR, "ImGui has a problem with Vulkan! (%s)",
+						 vk::to_string(result).c_str());
 	}
 	
 	GUI::GUI(Core& core, WindowHandle& windowHandle) :
diff --git a/modules/scene/src/vkcv/scene/Scene.cpp b/modules/scene/src/vkcv/scene/Scene.cpp
index b2b65a4a..76b7de78 100644
--- a/modules/scene/src/vkcv/scene/Scene.cpp
+++ b/modules/scene/src/vkcv/scene/Scene.cpp
@@ -364,7 +364,8 @@ namespace vkcv::scene {
 		asset::Scene asset_scene;
 		
 		if (!asset::loadScene(path.string(), asset_scene)) {
-			vkcv_log(LogLevel::ERROR, "Scene could not be loaded (%s)", path.c_str());
+			vkcv_log(LogLevel::ERROR, "Scene could not be loaded (%s)",
+							 path.string().c_str());
 			return create(core);
 		}
 		
diff --git a/modules/shader_compiler/src/vkcv/shader/Compiler.cpp b/modules/shader_compiler/src/vkcv/shader/Compiler.cpp
index 842ad6ab..5a7e60e6 100644
--- a/modules/shader_compiler/src/vkcv/shader/Compiler.cpp
+++ b/modules/shader_compiler/src/vkcv/shader/Compiler.cpp
@@ -14,7 +14,8 @@ namespace vkcv::shader {
 		const std::filesystem::path directory = generateTemporaryDirectoryPath();
 		
 		if (!std::filesystem::create_directory(directory)) {
-			vkcv_log(LogLevel::ERROR, "The directory could not be created (%s)", directory.c_str());
+			vkcv_log(LogLevel::ERROR, "The directory could not be created (%s)",
+							 directory.string().c_str());
 			return false;
 		}
 		
@@ -51,7 +52,8 @@ namespace vkcv::shader {
 		bool result = readTextFromFile(shaderPath, shaderCode);
 		
 		if (!result) {
-			vkcv_log(LogLevel::ERROR, "Loading shader failed: (%s)", shaderPath.string().c_str());
+			vkcv_log(LogLevel::ERROR, "Loading shader failed: (%s)",
+							 shaderPath.string().c_str());
 		}
 		
 		if (!includePath.empty()) {
@@ -61,7 +63,8 @@ namespace vkcv::shader {
 		}
 		
 		if (!result) {
-			vkcv_log(LogLevel::ERROR, "Shader compilation failed: (%s)", shaderPath.string().c_str());
+			vkcv_log(LogLevel::ERROR, "Shader compilation failed: (%s)",
+							 shaderPath.string().c_str());
 		}
 		
 		if (update) {
diff --git a/modules/shader_compiler/src/vkcv/shader/GLSLCompiler.cpp b/modules/shader_compiler/src/vkcv/shader/GLSLCompiler.cpp
index e469152f..e6823e5e 100644
--- a/modules/shader_compiler/src/vkcv/shader/GLSLCompiler.cpp
+++ b/modules/shader_compiler/src/vkcv/shader/GLSLCompiler.cpp
@@ -236,7 +236,7 @@ namespace vkcv::shader {
 							   false, false,
 							   messages, &preprocessedGLSL, includer)) {
 			vkcv_log(LogLevel::ERROR, "Shader preprocessing failed {\n%s\n%s\n}",
-				shader.getInfoLog(), shader.getInfoDebugLog());
+							 shader.getInfoLog(), shader.getInfoDebugLog());
 			return false;
 		}
 		
@@ -245,7 +245,7 @@ namespace vkcv::shader {
 
 		if (!shader.parse(&resources, 100, false, messages)) {
 			vkcv_log(LogLevel::ERROR, "Shader parsing failed {\n%s\n%s\n}",
-					 shader.getInfoLog(), shader.getInfoDebugLog());
+							 shader.getInfoLog(), shader.getInfoDebugLog());
 			return false;
 		}
 		
@@ -253,7 +253,7 @@ namespace vkcv::shader {
 		
 		if (!program.link(messages)) {
 			vkcv_log(LogLevel::ERROR, "Shader linking failed {\n%s\n%s\n}",
-					 shader.getInfoLog(), shader.getInfoDebugLog());
+							 shader.getInfoLog(), shader.getInfoDebugLog());
 			return false;
 		}
 		
diff --git a/modules/shader_compiler/src/vkcv/shader/HLSLCompiler.cpp b/modules/shader_compiler/src/vkcv/shader/HLSLCompiler.cpp
index 0d3991d1..96566479 100644
--- a/modules/shader_compiler/src/vkcv/shader/HLSLCompiler.cpp
+++ b/modules/shader_compiler/src/vkcv/shader/HLSLCompiler.cpp
@@ -232,7 +232,7 @@ namespace vkcv::shader {
 							   false, false,
 							   messages, &preprocessedHLSL, includer)) {
 			vkcv_log(LogLevel::ERROR, "Shader preprocessing failed {\n%s\n%s\n}",
-					 shader.getInfoLog(), shader.getInfoDebugLog());
+							 shader.getInfoLog(), shader.getInfoDebugLog());
 			return false;
 		}
 		
@@ -241,7 +241,7 @@ namespace vkcv::shader {
 		
 		if (!shader.parse(&resources, 100, false, messages)) {
 			vkcv_log(LogLevel::ERROR, "Shader parsing failed {\n%s\n%s\n}",
-					 shader.getInfoLog(), shader.getInfoDebugLog());
+							 shader.getInfoLog(), shader.getInfoDebugLog());
 			return false;
 		}
 		
@@ -249,7 +249,7 @@ namespace vkcv::shader {
 		
 		if (!program.link(messages)) {
 			vkcv_log(LogLevel::ERROR, "Shader linking failed {\n%s\n%s\n}",
-					 shader.getInfoLog(), shader.getInfoDebugLog());
+							 shader.getInfoLog(), shader.getInfoDebugLog());
 			return false;
 		}
 		
diff --git a/modules/shader_compiler/src/vkcv/shader/SlangCompiler.cpp b/modules/shader_compiler/src/vkcv/shader/SlangCompiler.cpp
index 7feff09b..0e610bb7 100644
--- a/modules/shader_compiler/src/vkcv/shader/SlangCompiler.cpp
+++ b/modules/shader_compiler/src/vkcv/shader/SlangCompiler.cpp
@@ -109,7 +109,7 @@ namespace vkcv::shader {
 		sessionDesc.targets = &targetDesc;
 		sessionDesc.targetCount = 1;
 
-		const char *searchPath = includePath.c_str();
+		const char *searchPath = includePath.string().c_str();
 		sessionDesc.searchPaths = &searchPath;
 		sessionDesc.searchPathCount = 1;
 
diff --git a/src/vkcv/Core.cpp b/src/vkcv/Core.cpp
index 3cefdab8..a402067d 100644
--- a/src/vkcv/Core.cpp
+++ b/src/vkcv/Core.cpp
@@ -896,7 +896,7 @@ namespace vkcv {
 
 		if ((result != vk::Result::eSuccess) && (result != vk::Result::eSuboptimalKHR)) {
 			vkcv_log(LogLevel::ERROR, "Swapchain presentation failed (%s)",
-					 vk::to_string(result).c_str());
+							 vk::to_string(result).c_str());
 		} else if (result == vk::Result::eSuboptimalKHR) {
 			vkcv_log(LogLevel::WARNING, "Swapchain presentation is suboptimal");
 			m_SwapchainManager->signalRecreation(swapchainHandle);
diff --git a/src/vkcv/DescriptorSetManager.cpp b/src/vkcv/DescriptorSetManager.cpp
index d4ffce74..74b4b291 100644
--- a/src/vkcv/DescriptorSetManager.cpp
+++ b/src/vkcv/DescriptorSetManager.cpp
@@ -165,7 +165,7 @@ namespace vkcv {
 
 			if (result != vk::Result::eSuccess) {
 				vkcv_log(LogLevel::ERROR, "Failed to create descriptor set (%s)",
-						 vk::to_string(result).c_str());
+								 vk::to_string(result).c_str());
 				return {};
 			}
 		};
diff --git a/src/vkcv/FeatureManager.cpp b/src/vkcv/FeatureManager.cpp
index fe7537be..e18598e0 100644
--- a/src/vkcv/FeatureManager.cpp
+++ b/src/vkcv/FeatureManager.cpp
@@ -627,13 +627,17 @@ namespace vkcv {
 		const char* clone = strclone(extension.c_str());
 
 		if (!clone) {
-			vkcv_log(LogLevel::WARNING, "Extension '%s' is not valid", extension.c_str());
+			vkcv_log(LogLevel::WARNING, "Extension '%s' is not valid",
+							 extension.c_str());
 			return false;
 		}
 
 		if (!isExtensionSupported(extension)) {
-			vkcv_log((required ? LogLevel::ERROR : LogLevel::WARNING),
-					 "Extension '%s' is not supported", extension.c_str());
+			vkcv_log(
+				(required ? LogLevel::ERROR : LogLevel::WARNING),
+				"Extension '%s' is not supported",
+				extension.c_str()
+			);
 
 			delete [] clone;
 			if (required) {
diff --git a/src/vkcv/File.cpp b/src/vkcv/File.cpp
index 702ae899..0b1328f4 100644
--- a/src/vkcv/File.cpp
+++ b/src/vkcv/File.cpp
@@ -62,7 +62,8 @@ namespace vkcv {
 		std::ofstream file (path.string(), std::ios::out);
 		
 		if (!file.is_open()) {
-			vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", path.c_str());
+			vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)",
+							 path.string().c_str());
 			return false;
 		}
 		
@@ -78,7 +79,8 @@ namespace vkcv {
 		std::ofstream file (path.string(), std::ios::out);
 		
 		if (!file.is_open()) {
-			vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", path.c_str());
+			vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)",
+							 path.string().c_str());
 			return false;
 		}
 		
@@ -97,7 +99,8 @@ namespace vkcv {
 		std::ofstream file (path.string(), std::ios::out);
 		
 		if (!file.is_open()) {
-			vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", path.c_str());
+			vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)",
+							 path.string().c_str());
 			return false;
 		}
 		
@@ -113,7 +116,8 @@ namespace vkcv {
 		std::ifstream file (path.string(), std::ios::ate);
 		
 		if (!file.is_open()) {
-			vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", path.c_str());
+			vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)",
+							 path.string().c_str());
 			return false;
 		}
 		
@@ -132,14 +136,16 @@ namespace vkcv {
 		std::ifstream file (path.string(), std::ios::ate);
 		
 		if (!file.is_open()) {
-			vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", path.c_str());
+			vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)",
+							 path.string().c_str());
 			return false;
 		}
 		
 		const std::streamsize fileSize = file.tellg();
 		
 		if (fileSize % sizeof(uint32_t) != 0) {
-			vkcv_log(LogLevel::ERROR, "The file is not a valid binary: %s", path.c_str());
+			vkcv_log(LogLevel::ERROR, "The file is not a valid binary: %s",
+							 path.string().c_str());
 			return false;
 		}
 		
@@ -160,7 +166,8 @@ namespace vkcv {
 		std::ifstream file (path.string(), std::ios::ate);
 		
 		if (!file.is_open()) {
-			vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", path.c_str());
+			vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)",
+							 path.string().c_str());
 			return false;
 		}
 		
diff --git a/src/vkcv/SwapchainManager.cpp b/src/vkcv/SwapchainManager.cpp
index 03dbdc01..008d2d1d 100644
--- a/src/vkcv/SwapchainManager.cpp
+++ b/src/vkcv/SwapchainManager.cpp
@@ -176,8 +176,12 @@ namespace vkcv {
 	static bool createVulkanSwapchain(const Context &context, const Window &window,
 									  SwapchainEntry &entry) {
 		if (!context.getFeatureManager().isExtensionActive(VK_KHR_SWAPCHAIN_EXTENSION_NAME)) {
-			vkcv_log(LogLevel::WARNING, "Extension required to create a swapchain: '%s'",
-					 VK_KHR_SWAPCHAIN_EXTENSION_NAME);
+			vkcv_log(
+				LogLevel::WARNING,
+				"Extension required to create a swapchain: '%s'",
+				VK_KHR_SWAPCHAIN_EXTENSION_NAME
+			);
+			
 			return false;
 		}
 		
diff --git a/src/vkcv/TypeGuard.cpp b/src/vkcv/TypeGuard.cpp
index 742071bb..91d6358e 100644
--- a/src/vkcv/TypeGuard.cpp
+++ b/src/vkcv/TypeGuard.cpp
@@ -16,17 +16,21 @@ namespace vkcv {
 		}
 
 		if (m_typeHash != hash) {
-			vkcv_log(LogLevel::WARNING,
-					 "Hash (%lu) does not match the specified hash of the type guard (%lu)", hash,
-					 m_typeHash);
+			vkcv_log(
+				LogLevel::WARNING,
+				"Hash (%lu) does not match the specified hash of the type guard (%lu)",
+				hash, m_typeHash
+			);
 
 			return false;
 		}
 
 		if (strcmp(m_typeName, name) != 0) {
-			vkcv_log(LogLevel::WARNING,
-					 "Name (%s) does not match the specified name of the type guard (%s)", name,
-					 m_typeName);
+			vkcv_log(
+				LogLevel::WARNING,
+				"Name (%s) does not match the specified name of the type guard (%s)",
+				name, m_typeName
+			);
 
 			return false;
 		} else {
@@ -37,9 +41,11 @@ namespace vkcv {
 
 	bool TypeGuard::checkTypeSize(size_t size) const {
 		if (m_typeSize != size) {
-			vkcv_log(LogLevel::WARNING,
-					 "Size (%lu) does not match the specified size of the type guard (%lu)", size,
-					 m_typeSize);
+			vkcv_log(
+				LogLevel::WARNING,
+				"Size (%lu) does not match the specified size of the type guard (%lu)",
+				size, m_typeSize
+			);
 
 			return false;
 		} else {
-- 
GitLab