Description
Environment
Operating System: MacOS x64 12.7.6
Version / Commit SHA: VDB 12.0.0 (from brew
)
Other: Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Describe the bug
After loading a grid using openvdb::io::Stream::getGrids()
, we're unable to dynamic_cast
(it returns null) it to the type openvdb::FloatGrid
, despite typeid(...).name()
reporting the same name for both.
To Reproduce
Steps to reproduce the behavior:
- Build your code with
-fvisibility=hidden
on a Mac. - Load a grid using
openvdb::io::Stream::getGrids()
then try todynamic_cast
it toopenvdb::FloatGrid
. - Observe that the cast returns null, but at the same time
typeid(openvdb::FloatGrid).name()
andtypeid(your_grid).name()
return the same string.
Expected behavior
The dynamic_cast
succeeds.
Additional context
This bug is caused by the missing __attribute__((__visibility__("default")))
annotation on your classes. Adding the annotation makes the cast pass.
I added annotations to the following classes:
openvdb::Grid
openvdb::tree::Tree
openvdb::tree::RootNode
openvdb::tree::InternalNode
openvdb::tree::LeafNode
This is the type that openvdb::FloatGrid
expands to, plus all its template arguments. I haven't tested if marking all those classes is necessary, but IIRC even the template arguments need to be marked.
I'm not well-versed in openvdb, so I don't know if any other classes have the same issue or not.