How to find out why the plugin registry is empty ( fails to load )?

Hello people,

I have a few users that have issues loading openusd files, the registry comes up empty. I am trying to add some logging to find out why.

Below is the code I am trying, trying an TfErrorMark and a TfDiagnosticMgr::Delegate. The two error conditions I simulated:

  1. delete the entire path I am adding for plugins ( absoluteUsdDirectory )

  2. adding some random text to the root pluginInfo.json

Neither of these triggers anything in these two detection mechanisms, does anyone see an obvious mistake here?

thanks,

Koen


class UsdDiagnosticDelegate : public TfDiagnosticMgr::Delegate
{
public:
	void IssueError(TfError const& err) override
	{
		TRACE_ERROR("USD Error: {}", err.GetCommentary().c_str());
	}

	void IssueWarning(TfWarning const& warning) override
	{
		TRACE_WARNING("USD Warning: {}", warning.GetCommentary().c_str());
	}

	void IssueStatus(TfStatus const& status) override
	{
		TRACE_INFO("USD Status: {}", status.GetCommentary().c_str());
	}

	void IssueFatalError(TfCallContext const& context, std::string const& msg) override
	{
		TRACE_ERROR("USD Fatal Error: {}", msg.c_str());
	}
};

/// Open a usd file and return the stage
UsdStageRefPtr openUsdFile(const StringBuf& depotPath)
{
	// Check if OpenUSD plugins have been registered
	// Usually this is done in PreInit_assets_usd but somehow this fails sometimes?
	if (PlugRegistry::GetInstance().GetAllPlugins().empty())
	{
		StringBuf absoluteUsdDirectory;
		FileSystem().resolveAbsolutePath("/tools/openusd/", absoluteUsdDirectory);
		
		// Create an error mark to capture any errors during registration
		TfErrorMark errorMark;

		// Install it before RegisterPlugins:
		UsdDiagnosticDelegate diagnosticDelegate;
		TfDiagnosticMgr::GetInstance().AddDelegate(&diagnosticDelegate);

		// try to register again
		PXR_NS::PlugRegistry::GetInstance().RegisterPlugins(absoluteUsdDirectory.c_str());

		// Check if any errors occurred
		if (!errorMark.IsClean())
		{
			TRACE_ERROR("OpenUSD plugin registration encountered errors:");

			// Iterate through all errors
			for (auto it = errorMark.GetBegin(); it != errorMark.GetEnd(); ++it)
			{
				const TfError& error = *it;
				TRACE_ERROR("  - {}: {}",
					error.GetErrorCodeAsString().c_str(),
					error.GetCommentary().c_str());
			}

			// Clear the errors after logging
			errorMark.Clear();
		}

		// Check if this is still empty
		if (PlugRegistry::GetInstance().GetAllPlugins().empty())
		{
			TRACE_ERROR("OpenUsd was not initialized properly from {}, can't load {}", absoluteUsdDirectory, depotPath);
			return nullptr;
		}
	}

Ah, I figured this out, the call to RegisterPlugins() had failed earlier so calling it again did not trigger the error anymore. Removing the first call made this one trigger on th TfErrorMark.

Sorry for the noise,

Koen