Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash happening in maya aiStandin when scrolling the timeline #1830

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

- [usd#1808](https://github.com/Autodesk/arnold-usd/issues/1808) - Fix the error "Cannot load _htoa_pygeo library required for volume rendering in Solaris" in Houdini 19.5+.
- [usd#1812](https://github.com/Autodesk/arnold-usd/issues/1812) - Improve Material network creation by caching the node entries and the osl code.
- [usd#1781](https://github.com/Autodesk/arnold-usd/issues/1781) - Fix a crash happening in a aiStandin usd when scrolling the timeline in maya.

## [7.2.5.1] - 2024-01-18

Expand Down
47 changes: 20 additions & 27 deletions libs/translator/reader/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,27 @@ namespace {
WorkDispatcher *dispatcher;
};
};
// global reader registry, will be used in the default case
static UsdArnoldReaderRegistry *s_readerRegistry = nullptr;
static int s_mustDeleteRegistry = 0;


static AtMutex s_globalReaderMutex;
static std::unordered_map<int, int> s_cacheRefCount;

UsdArnoldReader::UsdArnoldReader()
: _procParent(nullptr),
_universe(nullptr),
_convert(true),
_debug(false),
_threadCount(1),
_mask(AI_NODE_ALL),
_defaultShader(nullptr),
_hasRootPrim(false),
_readStep(READ_NOT_STARTED),
_purpose(UsdGeomTokens->render),
_dispatcher(nullptr),
_readerRegistry(new UsdArnoldReaderRegistry())
{}
UsdArnoldReader::~UsdArnoldReader()
{
if (s_mustDeleteRegistry && _registry) {
delete _registry;
s_mustDeleteRegistry = false;
_registry = s_readerRegistry;
}
// What do we want to do at destruction here ?
// Should we delete the created nodes in case there was no procParent ?
delete _readerRegistry;
}

void UsdArnoldReader::TraverseStage(UsdPrim *rootPrim, UsdArnoldReaderContext &context,
Expand Down Expand Up @@ -284,19 +289,7 @@ void UsdArnoldReader::ReadStage(UsdStageRefPtr stage, const std::string &path)
// and the eventual procedural mask set above
_mask = _mask & procMask;

// eventually use a dedicated registry
if (_registry == nullptr) {
// No registry was set (default), let's use the global one
{
std::lock_guard<AtMutex> guard(s_globalReaderMutex);
if (s_readerRegistry == nullptr) {
s_readerRegistry = new UsdArnoldReaderRegistry(); // initialize the global registry
s_readerRegistry->RegisterPrimitiveReaders();
}
}
_registry = s_readerRegistry;
} else
_registry->RegisterPrimitiveReaders();
_readerRegistry->RegisterPrimitiveReaders();

UsdPrim *rootPrimPtr = nullptr;

Expand Down Expand Up @@ -602,7 +595,7 @@ void UsdArnoldReader::ReadPrimitive(const UsdPrim &prim, UsdArnoldReaderContext
_renderSettings = objName;
}

UsdArnoldPrimReader *primReader = _registry->GetPrimReader(objType);
UsdArnoldPrimReader *primReader = _readerRegistry->GetPrimReader(objType);
if (primReader && (_mask & primReader->GetType())) {
if (_debug) {
std::string txt;
Expand Down Expand Up @@ -699,8 +692,8 @@ void UsdArnoldReader::SetProceduralParent(AtNode *node)
}

void UsdArnoldReader::CreateViewportRegistry(AtProcViewportMode mode, const AtParamValueMap* params) {
s_mustDeleteRegistry = true;
_registry = new UsdArnoldViewportReaderRegistry(mode, params);
delete _readerRegistry;
_readerRegistry = new UsdArnoldViewportReaderRegistry(mode, params);
}

void UsdArnoldReader::SetUniverse(AtUniverse *universe)
Expand Down
24 changes: 5 additions & 19 deletions libs/translator/reader/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,7 @@ class UsdArnoldReaderRegistry;

class UsdArnoldReader : public ProceduralReader {
public:
UsdArnoldReader()
: _procParent(nullptr),
_universe(nullptr),
_registry(nullptr),
_convert(true),
_debug(false),
_threadCount(1),
_mask(AI_NODE_ALL),
_defaultShader(nullptr),
_hasRootPrim(false),
_readStep(READ_NOT_STARTED),
_purpose(UsdGeomTokens->render),
_dispatcher(nullptr)
{
}
UsdArnoldReader();
~UsdArnoldReader();

void ReadStage(UsdStageRefPtr stage,
Expand All @@ -74,7 +60,7 @@ class UsdArnoldReader : public ProceduralReader {

void SetProceduralParent(AtNode *node) override;
void SetUniverse(AtUniverse *universe) override;
// void SetRegistry(UsdArnoldReaderRegistry *registry);

void CreateViewportRegistry(AtProcViewportMode mode, const AtParamValueMap* params) override;
void SetFrame(float frame) override;
void SetMotionBlur(bool motionBlur, float motionStart = 0.f, float motionEnd = 0.f) override;
Expand All @@ -89,7 +75,7 @@ class UsdArnoldReader : public ProceduralReader {
const UsdStageRefPtr &GetStage() const { return _stage; }
const std::vector<AtNode *> &GetNodes() const override { return _nodes; }
float GetFrame() const { return _time.frame; }
UsdArnoldReaderRegistry *GetRegistry() { return _registry; }
UsdArnoldReaderRegistry *GetRegistry() { return _readerRegistry; }
AtUniverse *GetUniverse() { return _universe; }
const AtNode *GetProceduralParent() const { return _procParent; }
bool GetDebug() const { return _debug; }
Expand Down Expand Up @@ -206,8 +192,6 @@ class UsdArnoldReader : public ProceduralReader {
private:
const AtNode *_procParent; // the created nodes are children of a procedural parent
AtUniverse *_universe; // only set if a specific universe is being used
UsdArnoldReaderRegistry *_registry; // custom registry used for this reader. If null, a global
// registry will be used.
TimeSettings _time;
bool _convert; // do we want to convert the primitives attributes
bool _debug;
Expand Down Expand Up @@ -235,6 +219,8 @@ class UsdArnoldReader : public ProceduralReader {
AtString _pxrMtlxPath; // environment variable PXR_MTLX_STDLIB_SEARCH_PATHS

unsigned int _id = 0; ///< Arnold shape ID for the procedural.
// Reader registry, will be used in the default case
UsdArnoldReaderRegistry *_readerRegistry = nullptr;
};

class UsdArnoldReaderThreadContext : public ArnoldAPIAdapter {
Expand Down