From 90c2056b182c823dd474687b4f25b4a89004b00f Mon Sep 17 00:00:00 2001 From: i-saint Date: Tue, 20 Mar 2018 05:21:00 +0900 Subject: [PATCH] fix compile error on non-Windows and improve log messages --- Plugin/abci/Foundation/aiLogger.cpp | 22 ++++++++++++--- Plugin/abci/Importer/aiContext.cpp | 43 +++++++++++++---------------- Plugin/abci/Importer/aiPolyMesh.cpp | 1 - Plugin/abci/pch.h | 13 +++++++-- 4 files changed, 47 insertions(+), 32 deletions(-) diff --git a/Plugin/abci/Foundation/aiLogger.cpp b/Plugin/abci/Foundation/aiLogger.cpp index 96e02fdc5..9cca2064a 100644 --- a/Plugin/abci/Foundation/aiLogger.cpp +++ b/Plugin/abci/Foundation/aiLogger.cpp @@ -3,16 +3,30 @@ void aiLogPrint(const char* fmt, ...) { - char buf[2048]; - va_list vl; va_start(vl, fmt); - vsprintf(buf, fmt, vl); #ifdef _WIN32 + char buf[2048]; + vsprintf(buf, fmt, vl); ::OutputDebugStringA(buf); ::OutputDebugStringA("\n"); #else - puts(buf); + vprintf(fmt, vl); +#endif + va_end(vl); +} + +void aiLogPrint(const wchar_t* fmt, ...) +{ + va_list vl; + va_start(vl, fmt); +#ifdef _WIN32 + wchar_t buf[2048]; + vswprintf(buf, fmt, vl); + ::OutputDebugStringW(buf); + ::OutputDebugStringW(L"\n"); +#else + vwprintf(fmt, vl); #endif va_end(vl); } diff --git a/Plugin/abci/Importer/aiContext.cpp b/Plugin/abci/Importer/aiContext.cpp index 2ffb0b049..e8f571517 100644 --- a/Plugin/abci/Importer/aiContext.cpp +++ b/Plugin/abci/Importer/aiContext.cpp @@ -198,56 +198,54 @@ void aiContext::reset() bool aiContext::load(const char *in_path) { auto path = NormalizePath(in_path); + auto wpath = L(in_path); - DebugLog("aiContext::load: '%s'", path.c_str()); + DebugLogW(L"aiContext::load: '%s'", wpath.c_str()); if (path == m_path && m_archive) { DebugLog("Context already loaded for gameObject with id %d", m_uid); return true; } - DebugLog("Alembic file path changed from '%s' to '%s'. Reset context.", m_path.c_str(), path.c_str()); - reset(); - - if (path.length() == 0) { + if (path.empty()) { return false; } m_path = path; - if (!m_archive.valid()) { - DebugLog("Archive '%s' not yet opened", in_path); - try { - DebugLog("Trying to open AbcCoreOgawa::ReadArchive..."); - - // open archive with wstring path and pass it to Abc::IArchive (Abc::IArchive can not use wstring path...) - auto wpath = L(path); - auto ifs = new std::ifstream(wpath.c_str(), std::ios::in | std::ios::binary); - m_streams.push_back(ifs); + // Abc::IArchive doesn't accept wide string path. so create file stream with wide string path and pass it. + // (VisualC++'s std::ifstream accepts wide string) + m_streams.push_back( +#ifdef WIN32 + new std::ifstream(wpath.c_str(), std::ios::in | std::ios::binary) +#else + new std::ifstream(path.c_str(), std::ios::in | std::ios::binary) +#endif + ); Alembic::AbcCoreOgawa::ReadArchive archive_reader(m_streams); m_archive = Abc::IArchive(archive_reader(m_path), Abc::kWrapExisting, Abc::ErrorHandler::kThrowPolicy); + DebugLog("Successfully opened Ogawa archive"); } catch (Alembic::Util::Exception e) { - DebugLog("Failed (%s)", e.what()); - - // hdf5 archive can not use external stream - // (that means if path contains wide characters, we can't open it. I couldn't find solution..) + // HDF5 archive doesn't accept external stream. so close it. + // (that means if path contains wide characters, it can't be opened. I couldn't find solution..) for (auto s : m_streams) { delete s; } m_streams.clear(); try { - DebugLog("Trying to open AbcCoreHDF5::ReadArchive..."); m_archive = Abc::IArchive(AbcCoreHDF5::ReadArchive(), path); + DebugLog("Successfully opened HDF5 archive"); } catch (Alembic::Util::Exception e2) { - DebugLog("Failed (%s)", e2.what()); + auto message = L(e2.what()); + DebugLogW(L"Failed to open archive: %s", message.c_str()); } } } else { - DebugLog("Archive '%s' already opened", in_path); + DebugLogW(L"Archive '%s' already opened", wpath.c_str()); } if (m_archive.valid()) { @@ -260,12 +258,9 @@ bool aiContext::load(const char *in_path) for (int i = 0; i < num_time_samplings; ++i) { m_timesamplings.emplace_back(aiCreateTimeSampling(m_archive, i)); } - - DebugLog("Succeeded"); return true; } else { - DebugError("Invalid archive '%s'", in_path); reset(); return false; } diff --git a/Plugin/abci/Importer/aiPolyMesh.cpp b/Plugin/abci/Importer/aiPolyMesh.cpp index c7a28ff57..6070a1f84 100644 --- a/Plugin/abci/Importer/aiPolyMesh.cpp +++ b/Plugin/abci/Importer/aiPolyMesh.cpp @@ -61,7 +61,6 @@ aiMeshTopology::aiMeshTopology() void aiMeshTopology::clear() { - DebugLog("Topology::clear()"); m_indices_sp.reset(); m_counts_sp.reset(); m_faceset_sps.clear(); diff --git a/Plugin/abci/pch.h b/Plugin/abci/pch.h index 691000def..a4f059fe4 100644 --- a/Plugin/abci/pch.h +++ b/Plugin/abci/pch.h @@ -27,13 +27,20 @@ #if defined(aiDebug) void aiLogPrint(const char* fmt, ...); - #define DebugLog(...) aiLogPrint("[Log] " __VA_ARGS__) - #define DebugWarning(...) aiLogPrint("[Warning]" __VA_ARGS__) - #define DebugError(...) aiLogPrint("[Error] " __VA_ARGS__) + void aiLogPrint(const wchar_t* fmt, ...); + #define DebugLog(...) aiLogPrint("abci Log: " __VA_ARGS__) + #define DebugWarning(...) aiLogPrint("abci Warning: " __VA_ARGS__) + #define DebugError(...) aiLogPrint("abci Error: " __VA_ARGS__) + #define DebugLogW(...) aiLogPrint(L"abci Log: " __VA_ARGS__) + #define DebugWarningW(...) aiLogPrint(L"abci Warning: " __VA_ARGS__) + #define DebugErrorW(...) aiLogPrint(L"abci Error: " __VA_ARGS__) #else #define DebugLog(...) #define DebugWarning(...) #define DebugError(...) + #define DebugLogW(...) + #define DebugWarningW(...) + #define DebugErrorW(...) #endif #ifdef _WIN32