Skip to content

Commit

Permalink
Fix for issue #97
Browse files Browse the repository at this point in the history
This makes sure primitive indices and other integer values use an
architecture/system-independent type.
  • Loading branch information
madmann91 committed Feb 1, 2025
1 parent d76b871 commit d5d4498
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/bvh/v2/bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ struct Bvh {
template <typename LeafFn = IgnoreArgs>
inline void refit(LeafFn&& = {});

template <typename IndexType = typename Index::Type>
inline void serialize(OutputStream&) const;

template <typename IndexType = typename Index::Type>
static inline Bvh deserialize(InputStream&);
};

Expand Down Expand Up @@ -215,24 +218,26 @@ void Bvh<Node>::refit(LeafFn&& leaf_fn) {
}

template <typename Node>
template <typename IndexType>
void Bvh<Node>::serialize(OutputStream& stream) const {
stream.write(nodes.size());
stream.write(prim_ids.size());
stream.write(static_cast<IndexType>(nodes.size()));
stream.write(static_cast<IndexType>(prim_ids.size()));
for (auto&& node : nodes)
node.serialize(stream);
for (auto&& prim_id : prim_ids)
stream.write(prim_id);
stream.write(static_cast<IndexType>(prim_id));
}

template <typename Node>
template <typename IndexType>
Bvh<Node> Bvh<Node>::deserialize(InputStream& stream) {
Bvh bvh;
bvh.nodes.resize(stream.read<size_t>());
bvh.prim_ids.resize(stream.read<size_t>());
bvh.nodes.resize(stream.read<IndexType>());
bvh.prim_ids.resize(stream.read<IndexType>());
for (auto& node : bvh.nodes)
node = Node::deserialize(stream);
for (auto& prim_id : bvh.prim_ids)
prim_id = stream.read<size_t>();
prim_id = stream.read<IndexType>();
return bvh;
}

Expand Down

0 comments on commit d5d4498

Please sign in to comment.