-
Notifications
You must be signed in to change notification settings - Fork 251
vsg::Object cast<T>() sometimes returns nullptr on macOS Sonoma arm64 Release builds #1575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…arm64 Release builds
|
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? |
|
I agree... I did, but I couldn't find anything. The object type is uintArray, here VulkanSceneGraph/src/vsg/text/Font.cpp Line 30 in 28b6b81
|
|
Could you have a look at this thread, I believe it touches upon the issue you are seeing: 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. |
… IDs during casting
|
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
|
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.
|
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):
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. |
src/vsg/CMakeLists.txt
Outdated
| target_compile_definitions(vsg INTERFACE VSG_SHARED_LIBRARY) | ||
| else() | ||
| if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
| if (VSG_USE_DYNAMIC_CAST) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where in CMake scripts is VSG_USE_DYNAMIC_CAST set & controlled? Is there a missing CMake option for this?
include/vsg/core/Object.h
Outdated
| #include <vsg/core/ref_ptr.h> | ||
| #include <vsg/core/type_name.h> | ||
|
|
||
| #ifdef VSG_USE_DYNAMIC_CAST |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use both VSG_USE_DYNAMIC_CAST and VSG_CAST_DYNAMIC?
FYI the include/vsg/core/Version.h is a CMake generated file that is set up via the src/vsg/core/Version.h.in file using various CMake options to control the settings. Perhaps this approach could avoid this clumsy ifdef?
include/vsg/core/Array.h
Outdated
| _size(0) | ||
| { | ||
| assign(data, offset, stride, l.size()); | ||
| assign(data, offset, stride, static_cast<uint32_t>(l.size())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume this is just a warning fix? If so should be applied independently from any other changes.
|
|
||
| template<typename T> | ||
| class Array : public Data | ||
| class VSG_DECLSPEC Array : public Data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Array requires VSG_DECLSPEC then Value, Array2D and Array3D will also require it.
|
After a crazy busy period of client work I'm now back catching up with PRs, sorry for taking so long to get back to this. I've done another code review and added comments into the various changes. I think some of the changes might be sensible to merge separately so if there are ones that aren't directly dependent on the dynamic_cast<> usage then it would be good to get these fixed as separate commits/PRs. I'm happy to do some of this, just point me in the right direction. |
move VSG_USE_DYNAMIC_CAST to version.h.in
|
I agree. I’ve removed the warning from this PR and added the suggestions you proposed. |
|
Changes look good, I have merged them as branch and will now try things out. It's near end of day so I'll probably not attempt to merge with master today: https://github.com/vsg-dev/VulkanSceneGraph/tree/hearga-fix-cast-arm64 I'm thinking we need a test for this to make sure we are getting the expected results and the performance differences. |
|
After review the CMake and Version.h.in I have changed to use CMake option and changed the capitalization of the define to be a more direct about what it maps too: 0d7cc5e |
|
I have created vsgcast test that can test the performance of running vsg::Object::cast<>: This is the output for when I build the VSG, vsgXchange and vsgExamples with VSG_USE_dynamic_cast OFF (default) and ON: robert@Vorlich:~/dev/VulkanSceneGraph$ vsgcast
Using typeid() based RTTI vsg::Object::cast<> implementation - faster than using dynamic_cast<>.
Time 938.224ms count = 100100000
Cast and traverse per second 106690930
robert@Vorlich:~/dev/VulkanSceneGraph$ vsgcast
Using dynamic_cast<> based RTTI vsg::Object::cast<> implementation.
Time 3470.26ms count = 100100000
Cast and traverse per second 28845095The dynamic_cast<> implementation is 2.8 times slower! With this testing and the refinements I've made I'm now happy with the branch so have merged with VSG master. |
Description
ref_ptr readObject(const char* propertyName)"
Type of change