From 0919faa3e4c22729d4cfe7e3a64e15bafcbc74e5 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Fri, 7 Aug 2026 21:33:46 +0800 Subject: [PATCH] fix: correct argument typo and path/error handling Fix --enable-consolelog flag, screenshot filter bug, paths to C APIs, add includes and gitignore entries, and improve ShellExecuteW failure detection. --- .gitignore | 1 + include/Cubed/gameplay/server_entity_manager.hpp | 1 + include/Cubed/tools/file_utils.hpp | 15 ++++++++++++--- include/Cubed/tools/sensitive_filter.hpp | 4 +++- src/app.cpp | 2 +- src/render/model_manager.cpp | 2 +- src/render/renderer.cpp | 8 ++++---- src/tools/shader_tools.cpp | 2 +- src/ui/screenshot_ui.cpp | 3 ++- 9 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 34d5687..e54445b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ *.pch *.sbr build/ +build_debug/ Build/ bin/ Debug/ diff --git a/include/Cubed/gameplay/server_entity_manager.hpp b/include/Cubed/gameplay/server_entity_manager.hpp index e5af786..f01e31b 100644 --- a/include/Cubed/gameplay/server_entity_manager.hpp +++ b/include/Cubed/gameplay/server_entity_manager.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace Cubed { class ServerWorld; class Session; diff --git a/include/Cubed/tools/file_utils.hpp b/include/Cubed/tools/file_utils.hpp index 66f5d4a..9f095bb 100644 --- a/include/Cubed/tools/file_utils.hpp +++ b/include/Cubed/tools/file_utils.hpp @@ -17,9 +17,18 @@ namespace Cubed::Tools { inline void open_file_manager(const std::filesystem::path& path) { #ifdef _WIN32 - - ShellExecuteW(nullptr, L"open", path.wstring().c_str(), nullptr, nullptr, - SW_SHOWNORMAL); + auto abs_path = std::filesystem::absolute(path); + if (!std::filesystem::exists(abs_path)) { + Logger::warn("Path does not exist: {}", abs_path.string()); + return; + } + HINSTANCE result = + ShellExecuteW(nullptr, L"open", abs_path.wstring().c_str(), nullptr, + nullptr, SW_SHOWNORMAL); + if ((INT_PTR)result <= 32) { + Logger::warn("ShellExecuteW failed for path: {}, error code: {}", + path.string(), (int)(INT_PTR)result); + } #elif __linux__ diff --git a/include/Cubed/tools/sensitive_filter.hpp b/include/Cubed/tools/sensitive_filter.hpp index bf93e9f..a0144c5 100644 --- a/include/Cubed/tools/sensitive_filter.hpp +++ b/include/Cubed/tools/sensitive_filter.hpp @@ -1,8 +1,10 @@ #pragma once - #include +#include +#include #include #include + namespace Cubed { class SensitiveFilter { public: diff --git a/src/app.cpp b/src/app.cpp index eb5422f..78b787b 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -187,7 +187,7 @@ void App::handle_argument(int argc, char** argv) { }}, {"--enable-filelog", [&](ArgParser&) { m_argument.enable_filelog = true; }}, - {"--enale-consolelog", + {"--enable-consolelog", [&](ArgParser&) { m_argument.enable_consolelog = true; }}, {"--direct-enter", [&](ArgParser&) { m_argument.direct_enter = true; }} diff --git a/src/render/model_manager.cpp b/src/render/model_manager.cpp index f11931a..9a81b26 100644 --- a/src/render/model_manager.cpp +++ b/src/render/model_manager.cpp @@ -88,7 +88,7 @@ ModelManager::Handle ModelManager::load_model(std::string_view model_name) { auto model = m_loader.load(path); fs::path anim_path = path; anim_path = anim_path.parent_path() / "animation.json"; - load_anim_config(model, anim_path); + load_anim_config(model, anim_path.string()); ModelMap::accessor acc; if (m_models.insert(acc, m_next++)) { acc->second = std::move(model); diff --git a/src/render/renderer.cpp b/src/render/renderer.cpp index d43b80d..1e02858 100644 --- a/src/render/renderer.cpp +++ b/src/render/renderer.cpp @@ -311,11 +311,11 @@ void Renderer::handle_screenshot() { fs::create_directories(path); fs::path image = path / std::format("screenshot {}.png", Tools::get_time_date_str()); - if (!stbi_write_png(image.c_str(), width, height, 4, flipped_pixels.data(), - width * 4)) { - Logger::error("Failed to write {} image", image.c_str()); + if (!stbi_write_png(image.string().c_str(), width, height, 4, + flipped_pixels.data(), width * 4)) { + Logger::error("Failed to write {} image", image.string()); } else { - Logger::info("save {} success!", image.c_str()); + Logger::info("save {} success!", image.string()); } } diff --git a/src/tools/shader_tools.cpp b/src/tools/shader_tools.cpp index e24f1aa..38b9589 100644 --- a/src/tools/shader_tools.cpp +++ b/src/tools/shader_tools.cpp @@ -184,7 +184,7 @@ ImageData load_image_data(const std::string& tex_image_path, bool check_exist, path = ASSETS_PATH + tex_image_path; } if (check_exist) { - ASSERT_MSG(fs::is_regular_file(path), path.c_str()); + ASSERT_MSG(fs::is_regular_file(path), path.string().c_str()); } unsigned char* data = nullptr; int width, height, channels; diff --git a/src/ui/screenshot_ui.cpp b/src/ui/screenshot_ui.cpp index 6fe3013..522cfcf 100644 --- a/src/ui/screenshot_ui.cpp +++ b/src/ui/screenshot_ui.cpp @@ -54,7 +54,8 @@ void ScreenshotUI::update_layout(int width, int height) { if (!fs::is_regular_file(entry)) { continue; } - if (!std::ranges::find(IMAGE_EXT, entry.path().extension())) { + if (std::ranges::find(IMAGE_EXT, entry.path().extension()) == + IMAGE_EXT.end()) { continue; } ImageInfo info;