uvatlas: updated to provide text description for HRESULTs

This commit is contained in:
Chuck Walbourn 2021-04-01 01:00:14 -07:00
parent 72ddabf02b
commit 16cce1642a

View File

@ -245,7 +245,6 @@ namespace
return 0;
}
void SearchForFiles(const wchar_t* path, std::list<SConversion>& files, bool recursive)
{
// Process files
@ -376,7 +375,6 @@ namespace
wprintf(L"\n");
}
void PrintUsage()
{
PrintLogo();
@ -436,6 +434,35 @@ namespace
PrintList(13, g_vertexColorFormats);
}
const wchar_t* GetErrorDesc(HRESULT hr)
{
static wchar_t desc[1024] = {};
LPWSTR errorText = nullptr;
DWORD result = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, nullptr,
static_cast<DWORD>(hr),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&errorText), 0, nullptr);
*desc = 0;
if (result > 0 && errorText)
{
swprintf_s(desc, L": %ls", errorText);
size_t len = wcslen(desc);
if (len >= 2)
{
desc[len - 2] = 0;
desc[len - 1] = 0;
}
if (errorText)
LocalFree(errorText);
}
return desc;
}
//--------------------------------------------------------------------------------------
HRESULT __cdecl UVAtlasCallback(float fPercentDone)
@ -492,7 +519,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (FAILED(hr))
{
wprintf(L"Failed to initialize COM (%08X)\n", static_cast<unsigned int>(hr));
wprintf(L"Failed to initialize COM (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
@ -898,7 +925,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
if (FAILED(hr))
{
wprintf(L" FAILED (%08X)\n", static_cast<unsigned int>(hr));
wprintf(L" FAILED (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
@ -921,7 +948,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->InvertUTexCoord();
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed inverting u texcoord (%08X)\n", static_cast<unsigned int>(hr));
wprintf(L"\nERROR: Failed inverting u texcoord (%08X%ls)\n",
static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
}
@ -931,7 +959,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->InvertVTexCoord();
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed inverting v texcoord (%08X)\n", static_cast<unsigned int>(hr));
wprintf(L"\nERROR: Failed inverting v texcoord (%08X%ls)\n",
static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
}
@ -941,7 +970,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->ReverseHandedness();
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed reversing handedness (%08X)\n", static_cast<unsigned int>(hr));
wprintf(L"\nERROR: Failed reversing handedness (%08X%ls)\n",
static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
}
@ -954,7 +984,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->GenerateAdjacency(epsilon);
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed generating adjacency (%08X)\n", static_cast<unsigned int>(hr));
wprintf(L"\nERROR: Failed generating adjacency (%08X%ls)\n",
static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
@ -971,7 +1002,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->Clean(true);
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed mesh clean (%08X)\n", static_cast<unsigned int>(hr));
wprintf(L"\nERROR: Failed mesh clean (%08X%ls)\n",
static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
else
@ -1018,7 +1050,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->ComputeNormals(flags);
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed computing normals (flags:%lX, %08X)\n", flags, static_cast<unsigned int>(hr));
wprintf(L"\nERROR: Failed computing normals (flags:%lX, %08X%ls)\n", flags,
static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
}
@ -1035,7 +1068,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->ComputeTangentFrame((dwOptions & (DWORD64(1) << OPT_CTF)) ? true : false);
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed computing tangent frame (%08X)\n", static_cast<unsigned int>(hr));
wprintf(L"\nERROR: Failed computing tangent frame (%08X%ls)\n",
static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
}
@ -1081,7 +1115,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
if (FAILED(hr))
{
wprintf(L"\nWARNING: Failed to load texture for IMT (%08X):\n%ls\n", static_cast<unsigned int>(hr), szTexFile);
wprintf(L"\nWARNING: Failed to load texture for IMT (%08X%ls):\n%ls\n",
static_cast<unsigned int>(hr), GetErrorDesc(hr), szTexFile);
}
else
{
@ -1090,11 +1125,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
ScratchImage floatImage;
if (img->format != DXGI_FORMAT_R32G32B32A32_FLOAT)
{
hr = Convert(*iimage.GetImage(0, 0, 0), DXGI_FORMAT_R32G32B32A32_FLOAT, TEX_FILTER_DEFAULT, TEX_THRESHOLD_DEFAULT, floatImage);
hr = Convert(*iimage.GetImage(0, 0, 0), DXGI_FORMAT_R32G32B32A32_FLOAT, TEX_FILTER_DEFAULT,
TEX_THRESHOLD_DEFAULT, floatImage);
if (FAILED(hr))
{
img = nullptr;
wprintf(L"\nWARNING: Failed converting texture for IMT (%08X):\n%ls\n", static_cast<unsigned int>(hr), szTexFile);
wprintf(L"\nWARNING: Failed converting texture for IMT (%08X%ls):\n%ls\n",
static_cast<unsigned int>(hr), GetErrorDesc(hr), szTexFile);
}
else
{
@ -1119,7 +1156,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (FAILED(hr))
{
IMTData.reset();
wprintf(L"WARNING: Failed to compute IMT from texture (%08X):\n%ls\n", static_cast<unsigned int>(hr), szTexFile);
wprintf(L"WARNING: Failed to compute IMT from texture (%08X%ls):\n%ls\n",
static_cast<unsigned int>(hr), GetErrorDesc(hr), szTexFile);
}
}
}
@ -1185,7 +1223,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (FAILED(hr))
{
IMTData.reset();
wprintf(L"WARNING: Failed to compute IMT from channel %ls (%08X)\n", szChannel, static_cast<unsigned int>(hr));
wprintf(L"WARNING: Failed to compute IMT from channel %ls (%08X%ls)\n",
szChannel, static_cast<unsigned int>(hr), GetErrorDesc(hr));
}
}
}
@ -1223,7 +1262,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
else
{
wprintf(L"\nERROR: Failed creating isocharts (%08X)\n", static_cast<unsigned int>(hr));
wprintf(L"\nERROR: Failed creating isocharts (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
}
@ -1237,14 +1276,14 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->UpdateFaces(nFaces, reinterpret_cast<const uint32_t*>(ib.data()));
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed applying atlas indices (%08X)\n", static_cast<unsigned int>(hr));
wprintf(L"\nERROR: Failed applying atlas indices (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
hr = inMesh->VertexRemap(vertexRemapArray.data(), vertexRemapArray.size());
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed applying atlas vertex remap (%08X)\n", static_cast<unsigned int>(hr));
wprintf(L"\nERROR: Failed applying atlas vertex remap (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
@ -1323,7 +1362,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->UpdateAttributes(nFaces, attr.get());
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed applying atlas attributes (%08X)\n", static_cast<unsigned int>(hr));
wprintf(L"\nERROR: Failed applying atlas attributes (%08X%ls)\n",
static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
}
@ -1333,7 +1373,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = inMesh->ReverseWinding();
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed reversing winding (%08X)\n", static_cast<unsigned int>(hr));
wprintf(L"\nERROR: Failed reversing winding (%08X%ls)\n", static_cast<unsigned int>(hr), GetErrorDesc(hr));
return 1;
}
}
@ -1449,7 +1489,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed write (%08X):-> '%ls'\n", static_cast<unsigned int>(hr), outputPath);
wprintf(L"\nERROR: Failed write (%08X%ls):-> '%ls'\n",
static_cast<unsigned int>(hr), GetErrorDesc(hr), outputPath);
return 1;
}
@ -1511,7 +1552,8 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
}
if (FAILED(hr))
{
wprintf(L"\nERROR: Failed uv mesh write (%08X):-> '%ls'\n", static_cast<unsigned int>(hr), outputPath);
wprintf(L"\nERROR: Failed uv mesh write (%08X%ls):-> '%ls'\n",
static_cast<unsigned int>(hr), GetErrorDesc(hr), outputPath);
return 1;
}
wprintf(L"uv mesh visualization '%ls'\n", outputPath);