Skip to content

Commit 0b7eb3c

Browse files
committed
Fix file paths with non-ASCII characters on windows
It was not possible to run an OpenUSD application from a directory with non-ASCII characters in it's name on windows. This is because LoadLibrary and std::ifstream were used with UTF-8-encoded file paths, while only system encoding and UTF-16 are supported. File paths are converted to UTF-16 now.
1 parent 6284755 commit 0b7eb3c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pxr/base/arch/library.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
#include "pxr/pxr.h"
9+
#include "pxr/base/arch/fileSystem.h"
910
#include "pxr/base/arch/library.h"
1011
#include "pxr/base/arch/errno.h"
1112

@@ -27,7 +28,7 @@ void* ArchLibraryOpen(const std::string &filename, int flag)
2728
{
2829
#if defined(ARCH_OS_WINDOWS)
2930
arch_lastLibraryError = 0;
30-
if (void* result = LoadLibrary(filename.c_str())) {
31+
if (void* result = LoadLibraryW(ArchWindowsUtf8ToUtf16(filename).c_str())) {
3132
return result;
3233
}
3334
else {

pxr/imaging/hio/glslfx.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,11 @@ static unique_ptr<istream>
232232
_CreateStreamForFile(string const& filePath)
233233
{
234234
if (TfIsFile(filePath)) {
235+
#if defined(ARCH_OS_WINDOWS)
236+
return make_unique<ifstream>(ArchWindowsUtf8ToUtf16(filePath));
237+
#else
235238
return make_unique<ifstream>(filePath);
239+
#endif
236240
}
237241

238242
const shared_ptr<ArAsset> asset = ArGetResolver().OpenAsset(

0 commit comments

Comments
 (0)