PhysX
PhysX copied to clipboard
Fix ambigous PxComputeHash on webassembly
Compiling with webassembly I get the following error:
In file included from /home/qt/work/qt/qtquick3dphysics/src/3rdparty/PhysX/source/physxextensions/src/ExtMetaData.cpp:41:
In file included from /home/qt/work/qt/qtquick3dphysics/src/3rdparty/PhysX/source/physxextensions/src/serialization/SnSerializationRegistry.h:36:
In file included from /home/qt/work/qt/qtquick3dphysics/src/3rdparty/PhysX/include/foundation/PxHashMap.h:32:
In file included from /home/qt/work/qt/qtquick3dphysics/src/3rdparty/PhysX/include/foundation/PxHashInternals.h:36:
/home/qt/work/qt/qtquick3dphysics/src/3rdparty/PhysX/include/foundation/PxHash.h:127:10: error: call to 'PxComputeHash' is ambiguous
2077: /home/qt/work/qt/qtquick3dphysics/src/3rdparty/PhysX/include/foundation/PxHash.h:57:26: note: candidate function
PX_FORCE_INLINE uint32_t PxComputeHash(const uint32_t key)
^
/home/qt/work/qt/qtquick3dphysics/src/3rdparty/PhysX/include/foundation/PxHash.h:69:26: note: candidate function
PX_FORCE_INLINE uint32_t PxComputeHash(const int32_t key)
^
/home/qt/work/qt/qtquick3dphysics/src/3rdparty/PhysX/include/foundation/PxHash.h:76:26: note: candidate function
PX_FORCE_INLINE uint32_t PxComputeHash(const uint64_t key)
^
I think this relates to the fact that webassembly integers are neither signed nor unsigned, see https://webassembly.github.io/spec/core/syntax/types.html
Anyhow, the fix is to simply use a template which look at the size of the type being hashed. This should work for both numbers and pointers. Note that this requires c++17.
I updated this to a c++11 solution now since that is what is used for PhysX.