From e2cd70e5d44d07619ab593ca16dfd51d7a8e42c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=88=98?= <40414978+PatriceJiang@users.noreply.github.com> Date: Fri, 2 Dec 2022 12:02:28 +0800 Subject: [PATCH] Bugfix: call debug::errorID with uint data type (#13626) * debug::errorID should accept uint as format argument * fix lint errors --- native/cocos/core/builtin/DebugInfos.cpp | 2 +- native/cocos/core/builtin/DebugInfos.cpp.in | 2 +- native/cocos/core/builtin/DebugInfos.h | 2 +- native/cocos/core/platform/Debug.cpp | 29 ++++++++++++++------- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/native/cocos/core/builtin/DebugInfos.cpp b/native/cocos/core/builtin/DebugInfos.cpp index db3e84d235..ca3bdaab8f 100644 --- a/native/cocos/core/builtin/DebugInfos.cpp +++ b/native/cocos/core/builtin/DebugInfos.cpp @@ -28,7 +28,7 @@ namespace cc { -ccstd::unordered_map debugInfos = { +ccstd::unordered_map debugInfos = { { 0100, "%s not yet implemented." }, { 0200, "You should specify a valid DOM canvas element." }, { 1006, "[Action step]. override me" }, diff --git a/native/cocos/core/builtin/DebugInfos.cpp.in b/native/cocos/core/builtin/DebugInfos.cpp.in index 019e086d40..5143749c0a 100644 --- a/native/cocos/core/builtin/DebugInfos.cpp.in +++ b/native/cocos/core/builtin/DebugInfos.cpp.in @@ -28,7 +28,7 @@ namespace cc { -ccstd::unordered_map debugInfos = { +ccstd::unordered_map debugInfos = { ${PLACE_HOLDER} }; }//namespace cc diff --git a/native/cocos/core/builtin/DebugInfos.h b/native/cocos/core/builtin/DebugInfos.h index 83f729040c..c4d7ebb090 100644 --- a/native/cocos/core/builtin/DebugInfos.h +++ b/native/cocos/core/builtin/DebugInfos.h @@ -30,6 +30,6 @@ namespace cc { -extern ccstd::unordered_map debugInfos; +extern ccstd::unordered_map debugInfos; } diff --git a/native/cocos/core/platform/Debug.cpp b/native/cocos/core/platform/Debug.cpp index ded12ea317..b577f1ff01 100644 --- a/native/cocos/core/platform/Debug.cpp +++ b/native/cocos/core/platform/Debug.cpp @@ -88,36 +88,44 @@ void printLog(DebugMode mode, const ccstd::string &fmt, ccstd::any *arr, int par if (pos != ccstd::string::npos && pos != (msg.length() - 1) && (msg[pos + 1] == 'd' || msg[pos + 1] == 's' || msg[pos + 1] == 'f')) { needToReplace = true; } - - if (arr[i].type() == typeid(const ccstd::string)) { - const ccstd::string s = ccstd::any_cast(arr[i]); + const auto &elemTypeId = arr[i].type(); + if (elemTypeId == typeid(const ccstd::string)) { + const auto s = ccstd::any_cast(arr[i]); if (needToReplace) { msg.replace(pos, 2, s); } else { msg += " " + s; } - } else if (arr[i].type() == typeid(ccstd::string)) { - ccstd::string s = ccstd::any_cast(arr[i]); + } else if (elemTypeId == typeid(ccstd::string)) { + auto s = ccstd::any_cast(arr[i]); if (needToReplace) { msg.replace(pos, 2, s); } else { msg += " " + s; } - } else if (arr[i].type() == typeid(int)) { + } else if (elemTypeId == typeid(int)) { int value = ccstd::any_cast(arr[i]); if (needToReplace) { msg.replace(pos, 2, std::to_string(value)); } else { msg += " " + std::to_string(value); } - } else if (arr[i].type() == typeid(float)) { + } else if (elemTypeId == typeid(unsigned int)) { + auto value = ccstd::any_cast(arr[i]); + if (needToReplace) { + msg.replace(pos, 2, std::to_string(value)); + } else { + msg += " " + std::to_string(value); + } + + } else if (elemTypeId == typeid(float)) { auto value = ccstd::any_cast(arr[i]); if (needToReplace) { msg.replace(pos, 2, std::to_string(value)); } else { msg += " " + std::to_string(value); } - } else if (arr[i].type() == typeid(const char *)) { + } else if (elemTypeId == typeid(const char *)) { ccstd::string s = ccstd::any_cast(arr[i]); if (needToReplace) { msg.replace(pos, 2, s); @@ -125,7 +133,8 @@ void printLog(DebugMode mode, const ccstd::string &fmt, ccstd::any *arr, int par msg += " " + s; } } else { - CC_LOG_ERROR("unsupport params data type"); + CC_LOG_ERROR("DebugInfos: unsupport params data type: '%s'", elemTypeId.name()); + CC_LOG_ERROR(" fmt: \"%s\", parameter index: %d", fmt.c_str(), i); return; } } @@ -134,4 +143,4 @@ void printLog(DebugMode mode, const ccstd::string &fmt, ccstd::any *arr, int par } } // namespace debug -} //namespace cc +} // namespace cc