diff --git a/include/Nazara/VulkanRenderer/Utils.inl b/include/Nazara/VulkanRenderer/Utils.inl index 4ae50130f..5bc99ab0c 100644 --- a/include/Nazara/VulkanRenderer/Utils.inl +++ b/include/Nazara/VulkanRenderer/Utils.inl @@ -520,7 +520,7 @@ namespace Nz UInt64 VulkanHandleToInteger(T handle) { if constexpr (std::is_pointer_v) - return static_cast(reinterpret_cast(handle)); + return static_cast(BitCast(handle)); else { static_assert(std::is_integral_v); diff --git a/src/Nazara/JoltPhysics3D/JoltCharacter.cpp b/src/Nazara/JoltPhysics3D/JoltCharacter.cpp index 211789547..1af3a6173 100644 --- a/src/Nazara/JoltPhysics3D/JoltCharacter.cpp +++ b/src/Nazara/JoltPhysics3D/JoltCharacter.cpp @@ -33,7 +33,7 @@ namespace Nz if (m_character) { JPH::BodyInterface& bodyInterface = m_world->GetPhysicsSystem()->GetBodyInterfaceNoLock(); - bodyInterface.SetUserData(m_character->GetBodyID(), SafeCast(reinterpret_cast(this))); + bodyInterface.SetUserData(m_character->GetBodyID(), SafeCast(BitCast(this))); } if (m_world) @@ -149,7 +149,7 @@ namespace Nz if (m_character) { JPH::BodyInterface& bodyInterface = m_world->GetPhysicsSystem()->GetBodyInterfaceNoLock(); - bodyInterface.SetUserData(m_character->GetBodyID(), SafeCast(reinterpret_cast(this))); + bodyInterface.SetUserData(m_character->GetBodyID(), SafeCast(BitCast(this))); } return *this; @@ -175,7 +175,7 @@ namespace Nz m_bodyIndex = m_character->GetBodyID().GetIndex(); JPH::BodyInterface& bodyInterface = m_world->GetPhysicsSystem()->GetBodyInterfaceNoLock(); - bodyInterface.SetUserData(m_character->GetBodyID(), SafeCast(reinterpret_cast(this))); + bodyInterface.SetUserData(m_character->GetBodyID(), SafeCast(BitCast(this))); m_world->RegisterStepListener(this); } diff --git a/src/Nazara/JoltPhysics3D/JoltConstraint3D.cpp b/src/Nazara/JoltPhysics3D/JoltConstraint3D.cpp index 991696a5a..74203e141 100644 --- a/src/Nazara/JoltPhysics3D/JoltConstraint3D.cpp +++ b/src/Nazara/JoltPhysics3D/JoltConstraint3D.cpp @@ -19,7 +19,7 @@ namespace Nz m_constraint(std::move(constraint.m_constraint)) { if (m_constraint) - m_constraint->SetUserData(SafeCast(reinterpret_cast(this))); + m_constraint->SetUserData(SafeCast(BitCast(this))); } JoltConstraint3D::~JoltConstraint3D() @@ -29,24 +29,24 @@ namespace Nz JoltRigidBody3D& JoltConstraint3D::GetBodyA() { - return *reinterpret_cast(static_cast(m_constraint->GetBody1()->GetUserData())); + return *BitCast(static_cast(m_constraint->GetBody1()->GetUserData())); } const JoltRigidBody3D& JoltConstraint3D::GetBodyA() const { - return *reinterpret_cast(static_cast(m_constraint->GetBody1()->GetUserData())); + return *BitCast(static_cast(m_constraint->GetBody1()->GetUserData())); } JoltRigidBody3D& JoltConstraint3D::GetBodyB() { NazaraAssert(!IsSingleBody(), "constraint is not attached to a second body"); - return *reinterpret_cast(static_cast(m_constraint->GetBody2()->GetUserData())); + return *BitCast(static_cast(m_constraint->GetBody2()->GetUserData())); } const JoltRigidBody3D& JoltConstraint3D::GetBodyB() const { NazaraAssert(!IsSingleBody(), "constraint is not attached to a second body"); - return *reinterpret_cast(static_cast(m_constraint->GetBody2()->GetUserData())); + return *BitCast(static_cast(m_constraint->GetBody2()->GetUserData())); } JoltPhysWorld3D& JoltConstraint3D::GetWorld() @@ -71,7 +71,7 @@ namespace Nz m_constraint = std::move(constraint.m_constraint); if (m_constraint) - m_constraint->SetUserData(SafeCast(reinterpret_cast(this))); + m_constraint->SetUserData(SafeCast(BitCast(this))); return *this; } @@ -92,7 +92,7 @@ namespace Nz assert(!m_constraint); m_constraint = std::move(constraint); m_constraint->SetEmbedded(); - m_constraint->SetUserData(SafeCast(reinterpret_cast(this))); + m_constraint->SetUserData(SafeCast(BitCast(this))); JPH::PhysicsSystem* physicsSystem = GetWorld().GetPhysicsSystem(); physicsSystem->AddConstraint(m_constraint.get()); diff --git a/src/Nazara/JoltPhysics3D/JoltPhysWorld3D.cpp b/src/Nazara/JoltPhysics3D/JoltPhysWorld3D.cpp index cc06e1048..3537d966b 100644 --- a/src/Nazara/JoltPhysics3D/JoltPhysWorld3D.cpp +++ b/src/Nazara/JoltPhysics3D/JoltPhysWorld3D.cpp @@ -185,7 +185,7 @@ namespace Nz JPH::Body& body = lock.GetBody(); - hitInfo.hitBody = reinterpret_cast(static_cast(body.GetUserData())); + hitInfo.hitBody = BitCast(static_cast(body.GetUserData())); if (auto fractionOpt = m_callback(hitInfo)) { @@ -235,7 +235,7 @@ namespace Nz JPH::Body& body = lock.GetBody(); - hitInfo.hitBody = reinterpret_cast(static_cast(body.GetUserData())); + hitInfo.hitBody = BitCast(static_cast(body.GetUserData())); if (auto fractionOpt = m_callback(hitInfo)) { @@ -285,7 +285,7 @@ namespace Nz JPH::Body& body = lock.GetBody(); - hitInfo.hitBody = reinterpret_cast(static_cast(body.GetUserData())); + hitInfo.hitBody = BitCast(static_cast(body.GetUserData())); hitInfo.hitNormal = FromJolt(body.GetWorldSpaceSurfaceNormal(result.mSubShapeID2, ToJolt(hitInfo.hitPosition))); if (auto fractionOpt = m_callback(hitInfo)) @@ -515,7 +515,7 @@ namespace Nz RaycastHit hitInfo; hitInfo.fraction = collector.mHit.GetEarlyOutFraction(); hitInfo.hitPosition = Lerp(from, to, hitInfo.fraction); - hitInfo.hitBody = reinterpret_cast(static_cast(body.GetUserData())); + hitInfo.hitBody = BitCast(static_cast(body.GetUserData())); hitInfo.hitNormal = FromJolt(body.GetWorldSpaceSurfaceNormal(collector.mHit.mSubShapeID2, rayCast.GetPointOnRay(collector.mHit.GetEarlyOutFraction()))); callback(hitInfo); diff --git a/src/Nazara/JoltPhysics3D/JoltRigidBody3D.cpp b/src/Nazara/JoltPhysics3D/JoltRigidBody3D.cpp index 835f34825..4eda46979 100644 --- a/src/Nazara/JoltPhysics3D/JoltRigidBody3D.cpp +++ b/src/Nazara/JoltPhysics3D/JoltRigidBody3D.cpp @@ -27,7 +27,7 @@ namespace Nz body.m_bodyIndex = std::numeric_limits::max(); if (m_body) - m_body->SetUserData(SafeCast(reinterpret_cast(this))); + m_body->SetUserData(SafeCast(BitCast(this))); } JoltRigidBody3D::~JoltRigidBody3D() @@ -319,7 +319,7 @@ namespace Nz body.m_bodyIndex = std::numeric_limits::max(); if (m_body) - m_body->SetUserData(SafeCast(reinterpret_cast(this))); + m_body->SetUserData(SafeCast(BitCast(this))); return *this; } @@ -431,7 +431,7 @@ namespace Nz creationSettings.mPosition = ToJolt(settings.position); creationSettings.mRotation = ToJolt(settings.rotation); - creationSettings.mUserData = SafeCast(reinterpret_cast(this)); + creationSettings.mUserData = SafeCast(BitCast(this)); } bool JoltRigidBody3D::ShouldActivate() const diff --git a/src/Nazara/OpenGLRenderer/OpenGLShaderModule.cpp b/src/Nazara/OpenGLRenderer/OpenGLShaderModule.cpp index 638ecf80f..374cb8270 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLShaderModule.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLShaderModule.cpp @@ -34,7 +34,7 @@ namespace Nz NazaraAssert(shaderStages == shaderStage, "when supplying GLSL, only one shader stage type can be specified"); auto& entry = m_shaders.emplace_back(); - entry.shader = GlslShader{ std::string(reinterpret_cast(source), std::size_t(sourceSize)) }; + entry.shader = GlslShader{ std::string(static_cast(source), sourceSize) }; entry.stage = shaderStage; break; } diff --git a/src/Nazara/Platform/SDL2/WindowImpl.cpp b/src/Nazara/Platform/SDL2/WindowImpl.cpp index 3216cb2c4..adc47acfa 100644 --- a/src/Nazara/Platform/SDL2/WindowImpl.cpp +++ b/src/Nazara/Platform/SDL2/WindowImpl.cpp @@ -124,7 +124,7 @@ namespace Nz } case WindowBackend::Cocoa: systemHandle = handle.cocoa.window; break; - case WindowBackend::X11: systemHandle = reinterpret_cast(std::uintptr_t(handle.x11.window)); break; + case WindowBackend::X11: systemHandle = BitCast(std::uintptr_t(handle.x11.window)); break; case WindowBackend::Windows: systemHandle = handle.windows.window; break; } diff --git a/src/Nazara/VulkanRenderer/VulkanShaderModule.cpp b/src/Nazara/VulkanRenderer/VulkanShaderModule.cpp index b12b0ad2b..5c21cce8e 100644 --- a/src/Nazara/VulkanRenderer/VulkanShaderModule.cpp +++ b/src/Nazara/VulkanRenderer/VulkanShaderModule.cpp @@ -95,8 +95,10 @@ namespace Nz case ShaderLanguage::SpirV: { + NazaraAssertFmt(sourceSize % sizeof(UInt32) == 0, "sourceSize must be a multiple of sizeof(UInt32), got {0}", sourceSize); + SpirvEntryPointExtractor extractor; - extractor.Decode(reinterpret_cast(source), sourceSize / sizeof(UInt32)); + extractor.Decode(static_cast(source), sourceSize / sizeof(UInt32)); nzsl::ShaderStageTypeFlags remainingStages = shaderStages; for (auto& entryPoint : extractor.entryPoints) diff --git a/src/Nazara/VulkanRenderer/VulkanSwapchain.cpp b/src/Nazara/VulkanRenderer/VulkanSwapchain.cpp index 53813aee1..08e91471c 100644 --- a/src/Nazara/VulkanRenderer/VulkanSwapchain.cpp +++ b/src/Nazara/VulkanRenderer/VulkanSwapchain.cpp @@ -530,7 +530,7 @@ namespace Nz { NazaraAssert(windowHandle.type == WindowBackend::Windows, "expected Windows window"); - HWND winHandle = reinterpret_cast(windowHandle.windows.window); + HWND winHandle = static_cast(windowHandle.windows.window); HINSTANCE instance = reinterpret_cast(GetWindowLongPtrW(winHandle, GWLP_HINSTANCE)); success = m_surface.Create(instance, winHandle); diff --git a/tests/UnitTests/Engine/Core/StringExtTest.cpp b/tests/UnitTests/Engine/Core/StringExtTest.cpp index ab2c5fabc..b7f467b07 100644 --- a/tests/UnitTests/Engine/Core/StringExtTest.cpp +++ b/tests/UnitTests/Engine/Core/StringExtTest.cpp @@ -100,7 +100,7 @@ SCENARIO("String", "[CORE][STRING]") { CHECK(Nz::TrimRight(Nz::PointerToString(nullptr), '0') == "0x"); - const void* ptr = reinterpret_cast(static_cast(0xDEADBEEF)); + const void* ptr = Nz::BitCast(static_cast(0xDEADBEEF)); CHECK(Nz::MatchPattern(Nz::PointerToString(ptr), "0x*DEADBEEF")); }