Skip to content

Commit 90c2056

Browse files
committed
fix compile error on non-Windows and improve log messages
1 parent 8755689 commit 90c2056

File tree

4 files changed

+47
-32
lines changed

4 files changed

+47
-32
lines changed

Plugin/abci/Foundation/aiLogger.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,30 @@
33

44
void aiLogPrint(const char* fmt, ...)
55
{
6-
char buf[2048];
7-
86
va_list vl;
97
va_start(vl, fmt);
10-
vsprintf(buf, fmt, vl);
118
#ifdef _WIN32
9+
char buf[2048];
10+
vsprintf(buf, fmt, vl);
1211
::OutputDebugStringA(buf);
1312
::OutputDebugStringA("\n");
1413
#else
15-
puts(buf);
14+
vprintf(fmt, vl);
15+
#endif
16+
va_end(vl);
17+
}
18+
19+
void aiLogPrint(const wchar_t* fmt, ...)
20+
{
21+
va_list vl;
22+
va_start(vl, fmt);
23+
#ifdef _WIN32
24+
wchar_t buf[2048];
25+
vswprintf(buf, fmt, vl);
26+
::OutputDebugStringW(buf);
27+
::OutputDebugStringW(L"\n");
28+
#else
29+
vwprintf(fmt, vl);
1630
#endif
1731
va_end(vl);
1832
}

Plugin/abci/Importer/aiContext.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -198,56 +198,54 @@ void aiContext::reset()
198198
bool aiContext::load(const char *in_path)
199199
{
200200
auto path = NormalizePath(in_path);
201+
auto wpath = L(in_path);
201202

202-
DebugLog("aiContext::load: '%s'", path.c_str());
203+
DebugLogW(L"aiContext::load: '%s'", wpath.c_str());
203204
if (path == m_path && m_archive) {
204205
DebugLog("Context already loaded for gameObject with id %d", m_uid);
205206
return true;
206207
}
207208

208-
DebugLog("Alembic file path changed from '%s' to '%s'. Reset context.", m_path.c_str(), path.c_str());
209-
210209
reset();
211-
212-
if (path.length() == 0) {
210+
if (path.empty()) {
213211
return false;
214212
}
215213

216214
m_path = path;
217-
218215
if (!m_archive.valid()) {
219-
DebugLog("Archive '%s' not yet opened", in_path);
220-
221216
try {
222-
DebugLog("Trying to open AbcCoreOgawa::ReadArchive...");
223-
224-
// open archive with wstring path and pass it to Abc::IArchive (Abc::IArchive can not use wstring path...)
225-
auto wpath = L(path);
226-
auto ifs = new std::ifstream(wpath.c_str(), std::ios::in | std::ios::binary);
227-
m_streams.push_back(ifs);
217+
// Abc::IArchive doesn't accept wide string path. so create file stream with wide string path and pass it.
218+
// (VisualC++'s std::ifstream accepts wide string)
219+
m_streams.push_back(
220+
#ifdef WIN32
221+
new std::ifstream(wpath.c_str(), std::ios::in | std::ios::binary)
222+
#else
223+
new std::ifstream(path.c_str(), std::ios::in | std::ios::binary)
224+
#endif
225+
);
228226

229227
Alembic::AbcCoreOgawa::ReadArchive archive_reader(m_streams);
230228
m_archive = Abc::IArchive(archive_reader(m_path), Abc::kWrapExisting, Abc::ErrorHandler::kThrowPolicy);
229+
DebugLog("Successfully opened Ogawa archive");
231230
}
232231
catch (Alembic::Util::Exception e) {
233-
DebugLog("Failed (%s)", e.what());
234-
235-
// hdf5 archive can not use external stream
236-
// (that means if path contains wide characters, we can't open it. I couldn't find solution..)
232+
// HDF5 archive doesn't accept external stream. so close it.
233+
// (that means if path contains wide characters, it can't be opened. I couldn't find solution..)
237234
for (auto s : m_streams) { delete s; }
238235
m_streams.clear();
239236

240237
try {
241-
DebugLog("Trying to open AbcCoreHDF5::ReadArchive...");
242238
m_archive = Abc::IArchive(AbcCoreHDF5::ReadArchive(), path);
239+
DebugLog("Successfully opened HDF5 archive");
243240
}
244241
catch (Alembic::Util::Exception e2) {
245-
DebugLog("Failed (%s)", e2.what());
242+
auto message = L(e2.what());
243+
DebugLogW(L"Failed to open archive: %s", message.c_str());
246244
}
247245
}
248246
}
249247
else {
250-
DebugLog("Archive '%s' already opened", in_path);
248+
DebugLogW(L"Archive '%s' already opened", wpath.c_str());
251249
}
252250

253251
if (m_archive.valid()) {
@@ -260,12 +258,9 @@ bool aiContext::load(const char *in_path)
260258
for (int i = 0; i < num_time_samplings; ++i) {
261259
m_timesamplings.emplace_back(aiCreateTimeSampling(m_archive, i));
262260
}
263-
264-
DebugLog("Succeeded");
265261
return true;
266262
}
267263
else {
268-
DebugError("Invalid archive '%s'", in_path);
269264
reset();
270265
return false;
271266
}

Plugin/abci/Importer/aiPolyMesh.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ aiMeshTopology::aiMeshTopology()
6161

6262
void aiMeshTopology::clear()
6363
{
64-
DebugLog("Topology::clear()");
6564
m_indices_sp.reset();
6665
m_counts_sp.reset();
6766
m_faceset_sps.clear();

Plugin/abci/pch.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@
2727

2828
#if defined(aiDebug)
2929
void aiLogPrint(const char* fmt, ...);
30-
#define DebugLog(...) aiLogPrint("[Log] " __VA_ARGS__)
31-
#define DebugWarning(...) aiLogPrint("[Warning]" __VA_ARGS__)
32-
#define DebugError(...) aiLogPrint("[Error] " __VA_ARGS__)
30+
void aiLogPrint(const wchar_t* fmt, ...);
31+
#define DebugLog(...) aiLogPrint("abci Log: " __VA_ARGS__)
32+
#define DebugWarning(...) aiLogPrint("abci Warning: " __VA_ARGS__)
33+
#define DebugError(...) aiLogPrint("abci Error: " __VA_ARGS__)
34+
#define DebugLogW(...) aiLogPrint(L"abci Log: " __VA_ARGS__)
35+
#define DebugWarningW(...) aiLogPrint(L"abci Warning: " __VA_ARGS__)
36+
#define DebugErrorW(...) aiLogPrint(L"abci Error: " __VA_ARGS__)
3337
#else
3438
#define DebugLog(...)
3539
#define DebugWarning(...)
3640
#define DebugError(...)
41+
#define DebugLogW(...)
42+
#define DebugWarningW(...)
43+
#define DebugErrorW(...)
3744
#endif
3845

3946
#ifdef _WIN32

0 commit comments

Comments
 (0)