From 813d0aecdda2627d3bdd612332ce5efc2f5f0afa Mon Sep 17 00:00:00 2001 From: Malcolm Tyrrell Date: Wed, 12 May 2021 12:43:24 +0100 Subject: [PATCH] Adjust warn --- code/AssetLib/Ogre/OgreStructs.cpp | 4 ++-- code/AssetLib/SIB/SIBImporter.cpp | 2 +- code/Common/DefaultLogger.cpp | 9 +++++---- include/assimp/Logger.hpp | 22 +++++++++++++--------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/code/AssetLib/Ogre/OgreStructs.cpp b/code/AssetLib/Ogre/OgreStructs.cpp index 90e2d4465..ce289c79c 100644 --- a/code/AssetLib/Ogre/OgreStructs.cpp +++ b/code/AssetLib/Ogre/OgreStructs.cpp @@ -545,7 +545,7 @@ aiMesh *SubMesh::ConvertToAssimpMesh(Mesh *parent) { dest->mNumUVComponents[0] = static_cast(uv1Element->ComponentCount()); dest->mTextureCoords[0] = new aiVector3D[dest->mNumVertices]; } else { - ASSIMP_LOG_WARN(Formatter::format() << "Ogre imported UV0 type " << uv1Element->TypeToString() << " is not compatible with Assimp. Ignoring UV."); + ASSIMP_LOG_WARN_F("Ogre imported UV0 type ", uv1Element->TypeToString(), " is not compatible with Assimp. Ignoring UV."); uv1 = 0; } } @@ -554,7 +554,7 @@ aiMesh *SubMesh::ConvertToAssimpMesh(Mesh *parent) { dest->mNumUVComponents[1] = static_cast(uv2Element->ComponentCount()); dest->mTextureCoords[1] = new aiVector3D[dest->mNumVertices]; } else { - ASSIMP_LOG_WARN(Formatter::format() << "Ogre imported UV0 type " << uv2Element->TypeToString() << " is not compatible with Assimp. Ignoring UV."); + ASSIMP_LOG_WARN_F("Ogre imported UV0 type ", uv2Element->TypeToString(), " is not compatible with Assimp. Ignoring UV."); uv2 = 0; } } diff --git a/code/AssetLib/SIB/SIBImporter.cpp b/code/AssetLib/SIB/SIBImporter.cpp index 6c1e5950b..1426fb73c 100644 --- a/code/AssetLib/SIB/SIBImporter.cpp +++ b/code/AssetLib/SIB/SIBImporter.cpp @@ -174,7 +174,7 @@ static void UnknownChunk(StreamReaderLE * /*stream*/, const SIBChunk &chunk) { static_cast(chunk.Tag & 0xff) }; - ASSIMP_LOG_WARN((Formatter::format(), "SIB: Skipping unknown '", ai_str_toprintable(temp, 4), "' chunk.")); + ASSIMP_LOG_WARN_F("SIB: Skipping unknown '", ai_str_toprintable(temp, 4), "' chunk."); } // Reads a UTF-16LE string and returns it at UTF-8. diff --git a/code/Common/DefaultLogger.cpp b/code/Common/DefaultLogger.cpp index aa13ca5ce..d2e9a2caf 100644 --- a/code/Common/DefaultLogger.cpp +++ b/code/Common/DefaultLogger.cpp @@ -197,13 +197,14 @@ void Logger::info(const char *message) { } // ---------------------------------------------------------------------------------- -void Logger::warn(const char *message) { - +void Logger::warnInternal(Assimp::Formatter::format f) { + std::string message = f; + // TODO: Should limit sizes in the formatter. // SECURITY FIX: see above - if (strlen(message) > MAX_LOG_MESSAGE_LENGTH) { + if (message.length() > MAX_LOG_MESSAGE_LENGTH) { return; } - return OnWarn(message); + return OnWarn(message.c_str()); } // ---------------------------------------------------------------------------------- diff --git a/include/assimp/Logger.hpp b/include/assimp/Logger.hpp index ee6eab507..f68c951fd 100644 --- a/include/assimp/Logger.hpp +++ b/include/assimp/Logger.hpp @@ -119,8 +119,10 @@ public: // ---------------------------------------------------------------------- /** @brief Writes a warning message * @param message Warn message*/ - void warn(const char* message); - void warn(const std::string &message); + template + void warn(T&&... args) { + warnInternal(Assimp::Formatter::format(), std::forward(args)...); + } // ---------------------------------------------------------------------- /** @brief Writes an error message @@ -225,6 +227,14 @@ protected: */ virtual void OnError(const char* message) = 0; +protected: + void warnInternal(Assimp::Formatter::format f); + + template + void warnInternal(Assimp::Formatter::format f, U&& u, T&&... args) { + warnInternal(std::move(f << std::forward(u)), std::forward(args)...); + } + protected: LogSeverity m_Severity; }; @@ -283,12 +293,6 @@ void Logger::error(const std::string &message) { return error(message.c_str()); } -// ---------------------------------------------------------------------------------- -inline -void Logger::warn(const std::string &message) { - return warn(message.c_str()); -} - // ---------------------------------------------------------------------------------- inline void Logger::info(const std::string &message) { @@ -299,7 +303,7 @@ void Logger::info(const std::string &message) { // ------------------------------------------------------------------------------------------------ #define ASSIMP_LOG_WARN_F(string, ...) \ - Assimp::DefaultLogger::get()->warn((Assimp::Formatter::format(string), __VA_ARGS__)) + Assimp::DefaultLogger::get()->warn((string, __VA_ARGS__)) #define ASSIMP_LOG_ERROR_F(string, ...) \ Assimp::DefaultLogger::get()->error((Assimp::Formatter::format(string), __VA_ARGS__))