Skip to content

Conversation

hearga
Copy link
Contributor

@hearga hearga commented Sep 2, 2025

Description

  • Addressed an issue where vsg::Object::cast() would sometimes return nullptr on macOS Sonoma (Apple Silicon, arm64) in Release builds.
  • Updated the casting logic to use dynamic_cast<T*>(), matching the approach already used in the previous function " template
    ref_ptr readObject(const char* propertyName)"

Type of change

  • Bug fix (non-breaking change which fixes an issue)

@robertosfield
Copy link
Collaborator

We need to get to the bottom of why cast<> is failing, not go around relacing all of it's usage across the VSG.

Is that are particular object type that is failing?

@hearga
Copy link
Contributor Author

hearga commented Sep 2, 2025

I agree... I did, but I couldn't find anything.

The object type is uintArray, here

input.readObject("charmap", charmap);

@robertosfield
Copy link
Collaborator

Could you have a look at this thread, I believe it touches upon the issue you are seeing:

#899

It looks like an issue with clang generating different type_info results for different libraries in certain circumstances. At the end of the above thread there are suggestions for solutions.

@hearga
Copy link
Contributor Author

hearga commented Sep 2, 2025

It works using explicit template instantiation. It resolves the different type_info hash IDs during casting.

    - vsg::Array<vsg::DrawIndexedIndirectCommand>
    - vsg::Array<vsg::VkGeometryInstance>
- cast l.size() to uint32_t in assign() to match parameter type and avoid warnings
- rename core/Array.cpp to core/ArrayInstantiations.cpp
@robertosfield
Copy link
Collaborator

Thanks for the changes, I've done a first past review and it feels like a rather heavy handed approach, forcing lots of extra code that we don't need other than for working around a problem with a specific compiler's build settings.

The changes would also need to be rolled out to all the other use of templates such as vsg::Value, Array2D, Array3D and perhaps even use of vsg::Inherit.

Did you test building as dynamic library?

…e hatch when desired; drop explicit instantiations

- CMake:
  * BUILD_SHARED_LIBS=OFF (static, Clang) -> by default define VSG_EXPORTS to export Array<T>;
    if VSG_USE_DYNAMIC_CAST is requested, define VSG_USE_DYNAMIC_CAST instead to switch cast<T>() to dynamic_cast.
- Remove ArrayInstantiations.cpp: explicit template instantiations are no longer needed.
@hearga
Copy link
Contributor Author

hearga commented Sep 9, 2025

Thanks for the review, I’ve reworked this to a minimal fix that targets the actual Clang issue (hidden visibility causing divergent &typeid(Array) across TUs):

  • Export the class: Array to stabilize typeid.
  • No explicit instantiations: removed ArrayInstantiations.cpp.
  • Opt-in escape hatch: VSG_USE_DYNAMIC_CAST switches cast() to dynamic_cast for those who prefer it.

If this approach looks good, we can apply the same small change to Value, Array2D/Array3D, etc., as needed, no project-wide mass changes required.

Shared libs: not tested, sorry, I have limited time to work on this; in shared builds, we already define the import/export macro, so the type info should be default-visible and typeid stable—no additional changes expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants