Skip to content

Commit

Permalink
Fix and improve string formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Jacki <jacki@thejackimonster.de>
  • Loading branch information
TheJackiMonster committed Sep 16, 2024
1 parent ca77a04 commit 306360c
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 51 deletions.
35 changes: 19 additions & 16 deletions modules/asset_loader/src/vkcv/asset/asset_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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;
}

Expand Down Expand Up @@ -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());

Expand All @@ -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());

Expand All @@ -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;
Expand All @@ -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;
}

Expand All @@ -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());

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}

Expand All @@ -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;
}
}
Expand Down
3 changes: 2 additions & 1 deletion modules/gui/src/vkcv/gui/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down
3 changes: 2 additions & 1 deletion modules/scene/src/vkcv/scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 6 additions & 3 deletions modules/shader_compiler/src/vkcv/shader/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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()) {
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions modules/shader_compiler/src/vkcv/shader/GLSLCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -245,15 +245,15 @@ 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;
}

program.addShader(&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;
}

Expand Down
6 changes: 3 additions & 3 deletions modules/shader_compiler/src/vkcv/shader/HLSLCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -241,15 +241,15 @@ 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;
}

program.addShader(&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;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/shader_compiler/src/vkcv/shader/SlangCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/vkcv/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/vkcv/DescriptorSetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
};
Expand Down
10 changes: 7 additions & 3 deletions src/vkcv/FeatureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 14 additions & 7 deletions src/vkcv/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
8 changes: 6 additions & 2 deletions src/vkcv/SwapchainManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading

0 comments on commit 306360c

Please sign in to comment.