Skip to content

Commit

Permalink
Fix case when hasField is called before yield node has finished execu…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
msz-rai committed Sep 27, 2024
1 parent adb120a commit fedb511
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/graph/NodesCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,14 @@ struct YieldPointsNode : IPointsNodeSingleInput
std::vector<rgl_field_t> getRequiredFieldList() const override { return fields; }

// Point cloud description
bool hasField(rgl_field_t field) const override { return results.contains(field); }
bool hasField(rgl_field_t field) const override
{
// The `results` map cannot be relied on because the hasField() may be called before the node has finished executing.
return std::find(fields.begin(), fields.end(), field) != fields.end();
}

// Data getters
IAnyArray::ConstPtr getFieldData(rgl_field_t field) override { return results.at(field); }
IAnyArray::ConstPtr getFieldData(rgl_field_t field) override;

HostPinnedArray<Field<XYZ_VEC3_F32>::type>::Ptr getXYZCache() { return xyzHostCache; }

Expand Down
9 changes: 9 additions & 0 deletions src/graph/YieldPointsNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

void YieldPointsNode::setParameters(const std::vector<rgl_field_t>& fields)
{
results.clear();
if (std::find(fields.begin(), fields.end(), RGL_FIELD_DYNAMIC_FORMAT) != fields.end()) {
throw InvalidAPIArgument("cannot yield field 'RGL_FIELD_DYNAMIC_FORMAT'"); // TODO: Yeah, but dummies are OK?
}
Expand All @@ -33,3 +34,11 @@ void YieldPointsNode::enqueueExecImpl()
xyzHostCache->getCount() * xyzHostCache->getSizeOf(), cudaMemcpyDefault, getStreamHandle()));
}
}

IAnyArray::ConstPtr YieldPointsNode::getFieldData(rgl_field_t field)
{
if (!results.contains(field)) {
throw std::runtime_error("Field data is not ready yet. It was requested without waiting for results.");
}
return results.at(field);
}

0 comments on commit fedb511

Please sign in to comment.