Skip to content

Commit

Permalink
Fix double resolver context initialization bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaScheller committed May 9, 2024
1 parent 4ae6d4e commit b6714ee
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
25 changes: 18 additions & 7 deletions src/CachedResolver/resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,20 @@ CachedResolver::_CreateDefaultContextForAsset(
if (!TfPathExists(resolvedPath)){
return ArResolverContext(_fallbackContext);
}
std::string resolvedPathStr = resolvedPath.GetPathString();
if(this->_GetCurrentContextObject<CachedResolverContext>() != nullptr){
TF_DEBUG(CACHEDRESOLVER_RESOLVER_CONTEXT).Msg("Resolver::_CreateDefaultContextForAsset('%s') - Skipping on same stage\n", assetPath.c_str());
return ArResolverContext(_fallbackContext);
if (this->_GetCurrentContextPtr() != nullptr)
{
if (TfDebug::IsEnabled(CACHEDRESOLVER_RESOLVER_CONTEXT))
{
if (this->_GetCurrentContextPtr() == &_fallbackContext)
{
TF_DEBUG(CACHEDRESOLVER_RESOLVER_CONTEXT).Msg("Resolver::_CreateDefaultContextForAsset('%s') - Reusing already bound default context on same stage\n", assetPath.c_str());
}
else
{
TF_DEBUG(CACHEDRESOLVER_RESOLVER_CONTEXT).Msg("Resolver::_CreateDefaultContextForAsset('%s') - Reusing already bound context CachedResolverContext('%s') on same stage\n", assetPath.c_str(), this->_GetCurrentContextPtr()->GetMappingFilePath().c_str());
}
}
return ArResolverContext(*this->_GetCurrentContextPtr());
}
auto map_iter = _sharedContexts.find(resolvedPath);
if(map_iter != _sharedContexts.end()){
Expand All @@ -317,9 +327,10 @@ CachedResolver::_CreateDefaultContextForAsset(
}
// Create new context
TF_DEBUG(CACHEDRESOLVER_RESOLVER_CONTEXT).Msg("Resolver::_CreateDefaultContextForAsset('%s') - Constructing new context\n", assetPath.c_str());
struct CachedResolverContextRecord record;
record.timestamp = this->_GetModificationTimestamp(assetPath, resolvedPath);
record.ctx = CachedResolverContext(resolvedPath);
struct CachedResolverContextRecord record
{
this->_GetModificationTimestamp(assetPath, resolvedPath), CachedResolverContext(resolvedPath)
};
_sharedContexts.insert(std::pair<std::string, CachedResolverContextRecord>(resolvedPath, record));
return ArResolverContext(record.ctx);
}
Expand Down
26 changes: 19 additions & 7 deletions src/FileResolver/resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,20 @@ FileResolver::_CreateDefaultContextForAsset(
if (!TfPathExists(resolvedPath)){
return ArResolverContext(_fallbackContext);
}
std::string resolvedPathStr = resolvedPath.GetPathString();
if(this->_GetCurrentContextObject<FileResolverContext>() != nullptr){
TF_DEBUG(FILERESOLVER_RESOLVER_CONTEXT).Msg("Resolver::_CreateDefaultContextForAsset('%s') - Skipping on same stage\n", assetPath.c_str());
return ArResolverContext(_fallbackContext);
if (this->_GetCurrentContextPtr() != nullptr)
{
if (TfDebug::IsEnabled(FILERESOLVER_RESOLVER_CONTEXT))
{
if (this->_GetCurrentContextPtr() == &_fallbackContext)
{
TF_DEBUG(FILERESOLVER_RESOLVER_CONTEXT).Msg("Resolver::_CreateDefaultContextForAsset('%s') - Reusing already bound default context on same stage\n", assetPath.c_str());
}
else
{
TF_DEBUG(FILERESOLVER_RESOLVER_CONTEXT).Msg("Resolver::_CreateDefaultContextForAsset('%s') - Reusing already bound context CachedResolverContext('%s') on same stage\n", assetPath.c_str(), this->_GetCurrentContextPtr()->GetMappingFilePath().c_str());
}
}
return ArResolverContext(*this->_GetCurrentContextPtr());
}
auto map_iter = _sharedContexts.find(resolvedPath);
if(map_iter != _sharedContexts.end()){
Expand All @@ -233,10 +243,12 @@ FileResolver::_CreateDefaultContextForAsset(
}
// Create new context
TF_DEBUG(FILERESOLVER_RESOLVER_CONTEXT).Msg("Resolver::_CreateDefaultContextForAsset('%s') - Constructing new context\n", assetPath.c_str());
std::string resolvedPathStr = resolvedPath.GetPathString();
std::string assetDir = TfGetPathName(TfAbsPath(resolvedPathStr));
struct FileResolverContextRecord record;
record.timestamp = this->_GetModificationTimestamp(assetPath, resolvedPath);
record.ctx = FileResolverContext(resolvedPath, std::vector<std::string>(1, assetDir));
struct FileResolverContextRecord record
{
this->_GetModificationTimestamp(assetPath, resolvedPath), FileResolverContext(resolvedPath, std::vector<std::string>(1, assetDir))
};
_sharedContexts.insert(std::pair<std::string, FileResolverContextRecord>(resolvedPath, record));
return ArResolverContext(record.ctx);
}
Expand Down
26 changes: 19 additions & 7 deletions src/PythonResolver/resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,20 @@ PythonResolver::_CreateDefaultContextForAsset(
if (!TfPathExists(resolvedPath)){
return ArResolverContext(_fallbackContext);
}
std::string resolvedPathStr = resolvedPath.GetPathString();
if(this->_GetCurrentContextObject<PythonResolverContext>() != nullptr){
TF_DEBUG(PYTHONRESOLVER_RESOLVER_CONTEXT).Msg("Resolver::_CreateDefaultContextForAsset('%s') - Skipping on same stage\n", assetPath.c_str());
return ArResolverContext(_fallbackContext);
if (this->_GetCurrentContextPtr() != nullptr)
{
if (TfDebug::IsEnabled(PYTHONRESOLVER_RESOLVER_CONTEXT))
{
if (this->_GetCurrentContextPtr() == &_fallbackContext)
{
TF_DEBUG(PYTHONRESOLVER_RESOLVER_CONTEXT).Msg("Resolver::_CreateDefaultContextForAsset('%s') - Reusing already bound default context on same stage\n", assetPath.c_str());
}
else
{
TF_DEBUG(PYTHONRESOLVER_RESOLVER_CONTEXT).Msg("Resolver::_CreateDefaultContextForAsset('%s') - Reusing already bound context CachedResolverContext('%s') on same stage\n", assetPath.c_str(), this->_GetCurrentContextPtr()->GetMappingFilePath().c_str());
}
}
return ArResolverContext(*this->_GetCurrentContextPtr());
}
auto map_iter = _sharedContexts.find(resolvedPath);
if(map_iter != _sharedContexts.end()){
Expand All @@ -153,10 +163,12 @@ PythonResolver::_CreateDefaultContextForAsset(
}
// Create new context
TF_DEBUG(PYTHONRESOLVER_RESOLVER_CONTEXT).Msg("Resolver::_CreateDefaultContextForAsset('%s') - Constructing new context\n", assetPath.c_str());
std::string resolvedPathStr = resolvedPath.GetPathString();
std::string assetDir = TfGetPathName(TfAbsPath(resolvedPathStr));
struct PythonResolverContextRecord record;
record.timestamp = this->_GetModificationTimestamp(assetPath, resolvedPath);
record.ctx = PythonResolverContext(resolvedPath);
struct PythonResolverContextRecord record
{
this->_GetModificationTimestamp(assetPath, resolvedPath), PythonResolverContext(resolvedPath)
};
_sharedContexts.insert(std::pair<std::string, PythonResolverContextRecord>(resolvedPath, record));
return ArResolverContext(record.ctx);
}
Expand Down

0 comments on commit b6714ee

Please sign in to comment.