Skip to content

Commit

Permalink
fix compile error on non-Windows and improve log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed Mar 19, 2018
1 parent 8755689 commit 90c2056
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 32 deletions.
22 changes: 18 additions & 4 deletions Plugin/abci/Foundation/aiLogger.cpp
Expand Up @@ -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);
}
43 changes: 19 additions & 24 deletions Plugin/abci/Importer/aiContext.cpp
Expand Up @@ -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()) {
Expand All @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion Plugin/abci/Importer/aiPolyMesh.cpp
Expand Up @@ -61,7 +61,6 @@ aiMeshTopology::aiMeshTopology()

void aiMeshTopology::clear()
{
DebugLog("Topology::clear()");
m_indices_sp.reset();
m_counts_sp.reset();
m_faceset_sps.clear();
Expand Down
13 changes: 10 additions & 3 deletions Plugin/abci/pch.h
Expand Up @@ -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
Expand Down

0 comments on commit 90c2056

Please sign in to comment.