Cannot open a USD stage from a path containing UTF-8 chars

Hi!

I am encountering issues when trying to open a stage from a path containing UTF-8 chars and I am running out of ideas of what the root cause is.

I am on Windows. The code scheme:

std::wstring Utf8ToWString(const std::string& utf8Str) 
{
	int size_needed = MultiByteToWideChar(CP_UTF8, 0, utf8Str.c_str(), -1, NULL, 0);
	std::wstring wstr(size_needed, 0);
	MultiByteToWideChar(CP_UTF8, 0, utf8Str.c_str(), -1, &wstr[0], size_needed);
	return wstr;
}

void openStage(const std::string& inputScenePath)
{
	if (std::filesystem::exists(Utf8ToWString(inputScenePath)))
	{
		std::cout << "File exists!\n";
	}

	UsdStageRefPtr stage = UsdStage::Open(inputScenePath);

	if (!stage)
	{
		throw std::runtime_error("Failed to open USD file");
	}
}

When inputScenePath contains ASCII chars only then the code works properly.

As soon as the path contains a non-standard UTF-8 character, its existence is detected properly (the app outputs File Exists) but the Open method returns an error: The system cannot find the file specified.

Any ideas about how to solve it?

Hi @glukoz, what version of OpenUSD are you using? Do you know what the format of layer you’re trying to open is? (ie. usdc vs. usda)

I am opening a usdc file.

The OpenUSD version is 25.02. I am building it from sources on my own.

@glukoz Have you tried a usda file by any chance?

I wonder if you’re running into the issue fixed here in 25.05-- Fix ArchGetFileName on windows for file paths with special characters by mnaehrig · Pull Request #3545 · PixarAnimationStudios/OpenUSD

1 Like

That was it! I upgraded to version 25.05 and the problem is now solved.

Thank you for your help!