Skip to content

[BUG] dynamic_cast fails on Mac because of missing visibility annotations #1974

Open
@adalisk-emikhaylov

Description

@adalisk-emikhaylov

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:

  1. Build your code with -fvisibility=hidden on a Mac.
  2. Load a grid using openvdb::io::Stream::getGrids() then try to dynamic_cast it to openvdb::FloatGrid.
  3. Observe that the cast returns null, but at the same time typeid(openvdb::FloatGrid).name() and typeid(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions